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

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

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

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

4 REPLIES 4
ballardw
Super User

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.

 

khalidamin
Obsidian | Level 7
@ballardw,
Thank you ... Will get back to you soon.

Happy Halloweens!
stat_sas
Ammonite | Level 13

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;

khalidamin
Obsidian | Level 7
Thank you so much 🙂

It worked perfectly.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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