Friday, December 30, 2011

proc freq v.s. proc sql

sasuser.sale2000 has variable origin and dest, if we want to list the unique combination of these two variables, we can use proc sql; select distinct ... Another method is using proc freq. It not only gives the no duplicated combination, but also sorts the result by the tables variables. The sas code is:

options formdlim='-' ;
proc sql;
    create table sqlrst as
    select distinct origin, dest
      from sasuser.sale2000
      order by origin, dest;

proc print data=sqlrst width=min;

proc freq data=sasuser.sale2000 noprint;
    tables origin*dest / list out=freq1;

proc print data=freq1(drop=count percent) width=min;