Say we have some data set called data1:
Name | Class | FS | Group | Good |
Will | A | Maths | 1 | Y |
Teddy | A | Phy | 2 | Y |
Jeremy | B | Bio | 3 | Y |
Bob | B | Maths | 2 | N |
What SAS code would you write to generate frequency tables for each levels of Good (Y and N)?
. i.e.
Good=Y | |||
Class | |||
Group | A | B | |
1 | 1 | 0 | |
2 | 1 | 1 | |
3 | 0 | 1 | |
Total | 2 | 2 |
Good=N | |||
Class | |||
Group | A | B | |
2 | 0 | 1 | |
Total | 0 | 1 |
data temp; input Name $ Class $ FS $ Group Good $ ; cards; Will A Maths 1 Y Teddy A Phy 2 Y Jeremy B Bio 3 Y Bob B Maths 2 N ; run; proc sort data=temp;by good;run; options missing=0; proc tabulate data=temp format=best4. missing; by good; class group class; table group all,class*n='' ; run;
Ksharp
I guess proc freq is not the right procedure to create this type of table. You should try proc tabulate. It has lot of options to create different type of tables. Also, proc report might do it.
data temp; input Name $ Class $ FS $ Group Good $ ; cards; Will A Maths 1 Y Teddy A Phy 2 Y Jeremy B Bio 3 Y Bob B Maths 2 N ; run; proc sort data=temp;by good;run; options missing=0; proc tabulate data=temp format=best4. missing; by good; class group class; table group all,class*n='' ; run;
Ksharp
keeping it simple, is it not just a case of using a "by good ;" statement in proc freq?
a very basic test
data d1 ;
input
Name $ Class $ FS $ Group Good $ ;
list;cards;
Will A Maths 1 Y
Teddy A Phy 2 Y
Jeremy B Bio 3 Y
Bob B Maths 2 N
;
proc sort ;
by good ;
run ;
proc freq ;
by good ;
table group * class ;
run;
And even simpler, we could eliminate the sort and by statement, and use a three level table statement:
data d1 ;
input
Name $ Class $ FS $ Group Good $ ;
list;cards;
Will A Maths 1 Y
Teddy A Phy 2 Y
Jeremy B Bio 3 Y
Bob B Maths 2 N
;
proc freq ;
table good * group * class /nopct norowpct nocolpct ;
run;
Steve Denham
Peter.C and Steve Denham
Yes. It would be more simple , but not exactly look like the output OP want.
Ksharp
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.