Creating loop for proc freq where statement in SAS

24 Views Asked by At

I have multiple conditional where statements for one variables such as:

where del="AG"; *argentina;

where del="BL"; *brazil;

etc.

I want to do the following proc freq:

proc freq data=latam;
tables hem*year/missing norow nopercent;
where del="AG"; *argentina;
run; 

looped through all of these values for DEL:

"AG"="ARGENTINA"
"BL"="BRAZIL"
"BO"="BOLIVIA"
"CK"="COLOMBIA"
"CL"="CHILE"
"CR"="COSTA RICA"
"CU"="CUBA"
"DR"="DOMINICAN REPUBLIC"
"EC"="ECUADOR"
"ES"="EL SALVADOR"
"GT"="GUATEMALA"
"HO"="HONDURAS"
"MX"="MEXICO"
"NQ"="NICARAGUA"
"PE"="PERU"
"PN"="PANAMA"
"PR"="PUERTO RICO"
"PY"="PARAGUAY"
"UY"="URUGUAY"
"VE"="VENEZUELA"

How can I write this so I don't have repeat the proc for each country?

2

There are 2 best solutions below

0
Richard On

Welcome to SAS. Use a BY statement.

proc sort data=latam;
  by del;
run;
proc freq data=latam;
  by del;
  tables hem*year/missing norow nopercent;
run; 
0
Tom On

If the data is sorted by DEL then you could use a BY statement.

proc freq data=latam;
  by del;
  tables hem*year/missing norow nopercent;
run; 

If not then you could have PROC FREQ do the organization for you by including DEL in the TABLES statement. That will cause PROC FREQ to produce a separate table for each value of DEL.

proc freq data=latam;
  tables del*hem*year/missing norow nopercent;
run;