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

Summary output table want: 

Questions All  Female  Male 
 Nn%Nn%Nn%
Q112866.75360.07571.4
Q211654.54250.07457.1

 

SubjectIDQ1 (1=Correct,
2=Incorrect)
Q2(1=Correct, 2=Incorrect)Gender (F=Female,
M=Male)
01-10611M
01-20511F
01-71412M
01-20122F
01-7031.F
01-10222M
01-50411M
01-10122M
01-10611F
01-20511M
01-71422F
01-20111M
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
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.

View solution in original post

6 REPLIES 6
ballardw
Super User
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.

Akter
Obsidian | Level 7

Thank you. Perfect! 

Just a quick question, Can we do the same using proc Report? 

Best regards,

Akter

ballardw
Super User

@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.

Akter
Obsidian | Level 7
Hi Ballardw, Thank you so much for the clarification.
Can I ask you another favour-I want one column header just below gender as
'Married' and 'Unmarried' with 'n', 'correct' and '%' for both Female and
Male using the sample proc tabulation procedure. How can I do that? I tried
to get it modifying your code a little bit but it was not working for me.
I really appreciate your support.
Respectfully,
Akter
Akter
Obsidian | Level 7
Never mind, I got it done. Thank you for your help.
ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 405 views
  • 0 likes
  • 2 in conversation