*Let's use macro variables to sort claims by TOS categories in descending size; libname stat541 '/home/grego1/STAT 541'; run; *Check counts for TOS categories; proc freq data=stat541.meddb; table tos; run; *Logic for macro variables; *TOS "A and B" creates a difficult problem otherwise; proc sql; create table tossort as select tos, count(*) as nct, compress(tos) as tosb from stat541.meddb group by tos order by nct descending; proc sql; select count(*) label="%bquote("# of Claim Types")" into :nrec trimmed from tossort; select tos label="Type of Service", tosb into :tos1-:tos&nrec, :tosb1-:tosb&nrec from tossort; quit; %put _user_; options symbolgen mprint mlogic; data meddb&tosb1 meddb&tosb2 meddb&tosb3 meddb&tosb4; set stat541.meddb; if tos="&tos1" then output meddb&tosb1; else if tos="&tos2" then output meddb&tosb2; else if tos="&tos3" then output meddb&tosb3; else output meddb&tosb4; run; *SELECT clause example; data a; input x @@; select; when(x<2) y=-x; when(x<3); when (x<4) y=10*x; otherwise y=100*x; end; datalines; 1.2 2.5 3.9 4.6 ; run; proc sql; select * from a; run; *Reading and writing only essential data; data fall95; input student 1-9 fmajor95 10-13 school 14-15 term95 16-20 fenrol95 $ 21-22@; if fenrol95='N' then input grad95 $ 23-24 race 25-26 stat95 27-28; else input race 23-24 stat95 25-26; /* The first student graduated in 4 years */ /* The second student transfered in year 2 */ datalines; 000271234 12323 3 E 2 1 000271234 12323 3 E 2 4 000271234 12323 3 E 2 4 000271234 12323 3 E 2 4 000271234 12323 3 N G 2 4 012345678 24512 3 E 4 1 012345678 24512 3 N N 4 2 ; run; proc print; run;