- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use group by
proc sql;
select sda, ffyear, count (distinct member_id) as count
from ELIGIBLE
group by sda, ffyear;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use group by
proc sql;
select sda, ffyear, count (distinct member_id) as count
from ELIGIBLE
group by sda, ffyear;
quit;