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

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%
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

5 REPLIES 5
data_null__
Jade | Level 19

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
Greek
Obsidian | Level 7

YES!

Thank you so much! Smiley Happy

data_null__
Jade | Level 19

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
Ksharp
Super User

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

data_null__
Jade | Level 19

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

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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