Help using Base SAS procedures

Proc report issue

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Proc report issue

Good afternoon,

I have browsed through a lot of resources about this, but I can't seem to fin a solution:

I have the following code that gives me the table below: I can't find a way to add percentages and totals!! Does anybody know how to modify my code?

proc report data=full_data nowd ;

column Likert (medicalcondition, (agegroup));

define medicalcondition / across ' ';

define agegroup/ across ' ';

define Likert / group style(column)=Header;

rbreak after /ol summarize

    style(summary)=Header{foreground=darkred};

run;

Table have:

Condition ACondition B
LikertParentChildParentChild
agree6937
neither agree nor disagree02.1
somewhat agree1353
somewhat disagree1000
strongly agree126129
20202020

Table want:

Condition ACondition BTotals
LikertParent%Child%Parent%Child%TotalTotal %
agree630%945%315%735%2531%
neither agree nor disagree00%210%00%15%34%
somewhat agree15%315%525%315%1215%
somewhat disagree15%00%00%00%11%
strongly agree1260%630%1260%945%3949%
20100%20100%20100%20100%80100%

Accepted Solutions
Solution
‎06-18-2015 04:12 PM
Respected Advisor
Posts: 3,799

Re: Proc report issue

Look at the documentation regarding the statistics called PCTN.  For example.

data summ;
   infile cards dsd;
  
input likert:$30. @;
   do medicalCondition=1,2;
     
do agegroup=1,2;
        
input freq @;
         output;
        
end;
     
end;
  
cards;              
agree,6,9,3,7
neither agree nor disagree,0,2,0,1
somewhat agree,1,3,5,3
somewhat disagree,1,0,0,0
strongly agree,12,6,12,9
;;;;
   run;
proc print;
  
run;

proc report data=summ nowd completerows list;
  
freq freq;
   column Likert (medicalcondition, (agegroup,(n pctn)));
   define medicalcondition / across ' ';
  
define agegroup/ across ' ';
  
define pctn / format=percent8.2;
  
define Likert / group style(column)=Header;
   rbreak after /ol summarize
  
style(summary)=Header{foreground=darkred};
   run;

6-18-2015 3-42-07 PM.png

View solution in original post


All Replies
Solution
‎06-18-2015 04:12 PM
Respected Advisor
Posts: 3,799

Re: Proc report issue

Look at the documentation regarding the statistics called PCTN.  For example.

data summ;
   infile cards dsd;
  
input likert:$30. @;
   do medicalCondition=1,2;
     
do agegroup=1,2;
        
input freq @;
         output;
        
end;
     
end;
  
cards;              
agree,6,9,3,7
neither agree nor disagree,0,2,0,1
somewhat agree,1,3,5,3
somewhat disagree,1,0,0,0
strongly agree,12,6,12,9
;;;;
   run;
proc print;
  
run;

proc report data=summ nowd completerows list;
  
freq freq;
   column Likert (medicalcondition, (agegroup,(n pctn)));
   define medicalcondition / across ' ';
  
define agegroup/ across ' ';
  
define pctn / format=percent8.2;
  
define Likert / group style(column)=Header;
   rbreak after /ol summarize
  
style(summary)=Header{foreground=darkred};
   run;

6-18-2015 3-42-07 PM.png
Contributor
Posts: 45

Re: Proc report issue

Posted in reply to data_null__

YES!

Thank you so much! Smiley Happy

Respected Advisor
Posts: 3,799

Re: Proc report issue

I didn't notice about the Total Column.

data summ;
   infile cards dsd;
  
input likert:$30. @;
   do medicalCondition=1,2;
     
do agegroup=1,2;
        
input freq @;
         output;
        
end;
     
end;
  
cards;              
agree,6,9,3,7
neither agree nor disagree,0,2,0,1
somewhat agree,1,3,5,3
somewhat disagree,1,0,0,0
strongly agree,12,6,12,9
;;;;
   run;
proc print;
  
run;
proc format;
  
value mcond 1='Cond A' 2='Cond B';
  
value agegr 1='Parent' 2='Child';
  
run;
proc report data=summ nowd missing completerows completecols list;
  
freq freq;
   column Likert (medicalcondition, agegroup,(n pctn)) ('Total' (n pctn));
   define medicalcondition / across ' ' format=mcond. ;
   define agegroup / across ' ' format=agegr.;
  
define pctn / format=percent8.1;
  
define Likert / group style(column)=Header;
   rbreak after /ol summarize
  
style(summary)=Header{foreground=darkred};
   run;

6-18-2015 4-27-35 PM.png
Super User
Posts: 10,020

Re: Proc report issue

Posted in reply to data_null__

John,

proc tabulate would be simpler to such scenario .

Code: Program

data summ;
   infile cards dsd;
   input likert:$30. @;
   do medicalCondition=1,2;
   do agegroup=1,2;
   input freq @;
   output;
   end;
   end;
   cards;  
agree,6,9,3,7
neither agree nor disagree,0,2,0,1
somewhat agree,1,3,5,3
somewhat disagree,1,0,0,0
strongly agree,12,6,12,9
;;;;
   run;
   proc format;
   value mcond 1='Cond A' 2='Cond B';
   value agegr 1='Parent' 2='Child';
   picture pct low-high='009.99%' (mult=100);
   run;
options missing='0';
proc tabulate data=summ;
class likert medicalCondition agegroup;
freq freq ;
table likert all,medicalCondition=''*agegroup=''*freq=''*(n colpctn*format=pct8.2) all*(n colpctn*format=pct8.2);
format medicalcondition mcond. agegroup agegr.;
run;

x.png

Xia Keshan

Respected Advisor
Posts: 3,799

Re: Proc report issue

The question was about PROC REPORT.  The fact that you think tabulate is simpler is irrelevant.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 350 views
  • 3 likes
  • 3 in conversation