Reputation: 187
I have a table with 4 variables: State (Alabama, Arizona and Arkansas), County, PovertyRate and PopulationDensity. I want a short macro with two arguments(state and county) that will print the data for any state/county combo. I came up with the following code which I tested for Covington county in Alabama and it gave me what it was supposed to but not sure if this is the most efficient/correct way to create this macro? Any feedback/suggestions would be appreciated. Thanks.
%macro state_county(state,county);
data NEW3;
set NEW;
where state="&state";
run;
data new4;
set NEW3;
where county="&county";
proc print data=NEW4 NOOBS;
run;
%mend state_county;
%state_county(Alabama,Covington);
Upvotes: 2
Views: 93
Reputation: 21264
If you only need to print, then only have a PRINT. You can put the WHERE directly into PROC PRINT, as either it's own statement or a data set option. If you have large data a data set option can be more efficient.
%macro state_county(state,county);
proc print data=NEW NOOBS;
where state="&state" and county="&county";
run;
%mend state_county;
%state_county(Alabama,Covington);
Upvotes: 2