Help using Base SAS procedures

Summary report

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Summary report

Hi everyone,

 

I am fairly new to SAS and need your help. I have a dataset of school children with grades and food habits. Food habit section has five variables. each variable tells the no. of time one particular food is take. For example,

 

IDGradeFood AFood BFood CFood D
1017YesNoYesYes
1028NoNoNoYes
1037YesYesNoYes

 

How can I make a table showing grade and food food habit? 

  Frequency
Grade 7 
 Yes6
 No2
Grade 8 
 Yes1
 No3

 

 

Would appreciate your help.

 

Thank you.

 

Khalid


Accepted Solutions
Solution
‎11-02-2015 09:51 AM
Trusted Advisor
Posts: 1,228

Re: Summary report

Posted in reply to khalidamin

Try this to generate desired output:

 

data have;
input ID Grade FoodA $ FoodB $ FoodC $ FoodD $;
datalines;
101 7 Yes No Yes Yes
102 8 No No No Yes
103 7 Yes Yes No Yes
;

proc transpose data=have out=want;
by id grade;
var FoodA FoodB FoodC FoodD;
run;

 

proc tabulate data=want;
class Grade col1;
table grade*col1=' ',n='Frequency';
run;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Summary report

Posted in reply to khalidamin

One way

proc tabulate data=have;
   class grade fooda foodb foodc foodd;
   table 
             grade *(fooda foodb foodc foodd),
             n
   ;
run;

this does all the foods at once. Grade * fooda , n ; would do just fooda.

 

Occasional Contributor
Posts: 14

Re: Summary report

@ballardw,
Thank you ... Will get back to you soon.

Happy Halloweens!
Solution
‎11-02-2015 09:51 AM
Trusted Advisor
Posts: 1,228

Re: Summary report

Posted in reply to khalidamin

Try this to generate desired output:

 

data have;
input ID Grade FoodA $ FoodB $ FoodC $ FoodD $;
datalines;
101 7 Yes No Yes Yes
102 8 No No No Yes
103 7 Yes Yes No Yes
;

proc transpose data=have out=want;
by id grade;
var FoodA FoodB FoodC FoodD;
run;

 

proc tabulate data=want;
class Grade col1;
table grade*col1=' ',n='Frequency';
run;

Occasional Contributor
Posts: 14

Re: Summary report

Thank you so much Smiley Happy

It worked perfectly.
🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 353 views
  • 2 likes
  • 3 in conversation