Hello SAS community,
when I run
proc freq data=have;
tables month * Q1 * Q2 / list nocum;
run;
I get the following (showing partial output)
|
month |
Q1 |
Q2 |
Frequency |
Percent |
|
Feb-20 |
1 |
1 |
92 |
17.29 |
|
Mar-20 |
1 |
1 |
41 |
7.71 |
|
Sep-20 |
1 |
0 |
9 |
1.69 |
|
Sep-20 |
1 |
1 |
34 |
6.39 |
|
Oct-20 |
1 |
0 |
15 |
2.82 |
|
Oct-20 |
1 |
1 |
39 |
7.33 |
|
Nov-20 |
1 |
0 |
25 |
4.7 |
|
Nov-20 |
1 |
1 |
20 |
3.76 |
I would like to get the count and % (no decimal places) of subjects who answered one or both questions each month, e.g. in Nov, out of a total of 45 subjects, 44% answered both and 56% answered Q1 only.
Should I use proc report and if so how?
I'm running SAS 9.4 on Windows.
Any help would be appreciated!
Margaret
Sounds like you might want ROWPCTN in Proc TABULATE.
Example:
data have;
call streaminit(2020);
do date = '01jan2020'd to '31dec2020'd;
do rep = 1 to rand('integer',2,5);
Q1 = rand('uniform') < 0.6;
Q2 = rand('uniform') < 0.4;
output;
end;
end;
run;
proc tabulate data=have;
class date q1 q2;
format date monyy6.;
table
date
,
q1='Q1 * Q2'*q2=''*n=''
q1='Q1 * Q2'*q2='' * rowpctn * f=3.
;
run;
Produces
Sounds like you might want ROWPCTN in Proc TABULATE.
Example:
data have;
call streaminit(2020);
do date = '01jan2020'd to '31dec2020'd;
do rep = 1 to rand('integer',2,5);
Q1 = rand('uniform') < 0.6;
Q2 = rand('uniform') < 0.4;
output;
end;
end;
run;
proc tabulate data=have;
class date q1 q2;
format date monyy6.;
table
date
,
q1='Q1 * Q2'*q2=''*n=''
q1='Q1 * Q2'*q2='' * rowpctn * f=3.
;
run;
Produces
Here is an example .
proc sql;
create table want as
select sex,age,
count(*)/(select count(*) from sashelp.class where sex=a.sex) as per format=percent8.2
from sashelp.class as a
group by sex,age;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.