Summary output table want:
| Questions | All | Female | Male | ||||||
| N | n | % | N | n | % | N | n | % | |
| Q1 | 12 | 8 | 66.7 | 5 | 3 | 60.0 | 7 | 5 | 71.4 |
| Q2 | 11 | 6 | 54.5 | 4 | 2 | 50.0 | 7 | 4 | 57.1 |
| SubjectID | Q1 (1=Correct, 2=Incorrect) | Q2(1=Correct, 2=Incorrect) | Gender (F=Female, M=Male) |
| 01-106 | 1 | 1 | M |
| 01-205 | 1 | 1 | F |
| 01-714 | 1 | 2 | M |
| 01-201 | 2 | 2 | F |
| 01-703 | 1 | . | F |
| 01-102 | 2 | 2 | M |
| 01-504 | 1 | 1 | M |
| 01-101 | 2 | 2 | M |
| 01-106 | 1 | 1 | F |
| 01-205 | 1 | 1 | M |
| 01-714 | 2 | 2 | F |
| 01-201 | 1 | 1 | M |
data have;
input SubjectID $ Q1 Q2 Gender $;
datalines;
01-106 1 1 M
01-205 1 1 F
01-714 1 2 M
01-201 2 2 F
01-703 1 . F
01-102 2 2 M
01-504 1 1 M
01-101 2 2 M
01-106 1 1 F
01-205 1 1 M
01-714 2 2 F
01-201 1 1 M
;
data need;
set have;
array q (*) q1 q2;
do i=1 to dim(q);
if q[i] then q[i]=(q[i]=1);
end;
drop i;
run;
proc format;
value $gender
'F'='Female'
'M'='Male'
;
proc tabulate data=need;
class gender;
format gender $gender.;
var q1 q2;
table q1 q2,
(All gender=' ') *(n='n' sum='Correct'*f=best. mean='%'*f=percent8.1)
/misstext=' '
;
run;
Not going to make a data set from CSV as my choices may vary from yours and would not duplicate. So using some of the data as shown.
When you want a two level variable to only report on one meaning creating a 1/0 coded numeric is often a good choice because the N statistic still works, sum becomes the number of ones values and mean is the decimal percentage of ones.
data have;
input SubjectID $ Q1 Q2 Gender $;
datalines;
01-106 1 1 M
01-205 1 1 F
01-714 1 2 M
01-201 2 2 F
01-703 1 . F
01-102 2 2 M
01-504 1 1 M
01-101 2 2 M
01-106 1 1 F
01-205 1 1 M
01-714 2 2 F
01-201 1 1 M
;
data need;
set have;
array q (*) q1 q2;
do i=1 to dim(q);
if q[i] then q[i]=(q[i]=1);
end;
drop i;
run;
proc format;
value $gender
'F'='Female'
'M'='Male'
;
proc tabulate data=need;
class gender;
format gender $gender.;
var q1 q2;
table q1 q2,
(All gender=' ') *(n='n' sum='Correct'*f=best. mean='%'*f=percent8.1)
/misstext=' '
;
run;
Not going to make a data set from CSV as my choices may vary from yours and would not duplicate. So using some of the data as shown.
When you want a two level variable to only report on one meaning creating a 1/0 coded numeric is often a good choice because the N statistic still works, sum becomes the number of ones values and mean is the decimal percentage of ones.
Thank you. Perfect!
Just a quick question, Can we do the same using proc Report?
Best regards,
Akter
@Akter wrote:
Thank you. Perfect!
Just a quick question, Can we do the same using proc Report?
Best regards,
Akter
Yes. BUT because you have two different variables in a column, your Q1 and Q2, you would need to completely reshape your data set so that t Q1 and Q2 became the value of a different variable.
Report wants a column to be a single variable or statistic.
Multiple nestings in both row and column are one of Proc Tabulates strong points (as well as multiple differently structured table statements in a single procedure call). However to go with that it does not allow you to use the result of a row/column calculation in another location which Proc Report does.
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 lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.