I have a dataset that looks like the following:
ID MONTH VAR
1 1 2
1 2 2
1 3 1
2 1 2
2 2 2
2 3 2
3 1 1
3 2 1
3 3 1
I need to get a count of ID's where VAR=1 for at least one of the months.
I'm not a very advanced user.
Is there code that could easily accomplish what I'm looking for?
This might be the easiest way:
proc sql;
select count(distinct id) from your_dataset where var=1;
quit;
If you need just the count then use PROC SQL.
data one;
infile datalines;
input ID MONTH VAR;
datalines;
1 1 2
1 2 2
1 3 1
2 1 2
2 2 2
2 3 2
3 1 1
3 2 1
3 3 1
;
run;
proc sql;
select distinct count(id) INTO: count
from one
where var=1 and month=1;
quit;
This might be the easiest way:
proc sql;
select count(distinct id) from your_dataset where var=1;
quit;
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.
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.