Hi Everybody! I am fairly new to SAS and still have trouble with some things.
I have a dataset and want to get the distinct count of members based on two variables. Variable 1 (SDA) has 13 values and Variable 2 (FFYEAR) HAS 7 values. Instead of writing out the code 91 different times (13 X 7 = 91) for all the different combination of variables, is there a way I can write the code once but refer to all the different values in the variable?
I am using SAS 9.2 and here is the basic structure of my current code:
proc sql;
select count (distinct member_id) as count
from ELIGIBLE
where sda='A' AND ffyear=2009;
quit;
I want to avoid having to write the code over and over for each combination of variable values.
Use group by
proc sql;
select sda, ffyear, count (distinct member_id) as count
from ELIGIBLE
group by sda, ffyear;
quit;
I think you need to provide some example data and what you expect the output to look like.
You may be looking for GROUP BY if you really need to do sql;
Or possibly:
proc summary data=eligible nway;
class SDA FFYEAR Member_id;
output out=want (drop=_type_ rename=(_freq_=Count));
run;
Use group by
proc sql;
select sda, ffyear, count (distinct member_id) as count
from ELIGIBLE
group by sda, ffyear;
quit;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.