Dear,
I am trying to calculate number of subjects based on different conditions.
Some one helped me with code with one condition. I need to count number of subjects by several variables eg: where (aflag='Y'). How to code to get the output which includes all OBS in one proc statement . Thank you
Code:
proc sql;
create table one as
select *, (select count(distinct id) from data1 where flag="Y") as NS
from data1;
quit;
Data1
id flag AFlag
1 Y
1 Y
1 Y
2 Y Y
2 Y
3
4
5 Y
6 Y
7 Y Y
output expected:
Data2
id flag NS NS2
1 Y 4
1 Y 4
1 Y 4
2 Y 4 3
2 Y 4 3
3
4
5 Y 4
6 3
7 Y 4 3
output getting
Data1
id flag NS
1 Y 4
1 Y 4
1 Y 4
2 Y 4
2 Y 4
5 Y 4
7 Y 4
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.