BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TXSASneophyte
Obsidian | Level 7

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use group by

 

proc sql;
select sda, ffyear, count (distinct member_id) as count
from ELIGIBLE
group by sda, ffyear;
quit; 
PG

View solution in original post

2 REPLIES 2
ballardw
Super User

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;
PGStats
Opal | Level 21

Use group by

 

proc sql;
select sda, ffyear, count (distinct member_id) as count
from ELIGIBLE
group by sda, ffyear;
quit; 
PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 27213 views
  • 1 like
  • 3 in conversation