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

Say we have some data set called data1:

NameClassFSGroupGood
WillAMaths1Y
TeddyAPhy2Y
JeremyBBio3Y
BobBMaths2N


What SAS code would you write to generate frequency tables for each levels of Good (Y and N)?

. i.e.

Good=Y
Class
GroupAB
110
211
301
Total22

Good=N
Class
GroupAB
201
Total01
1 ACCEPTED SOLUTION

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

View solution in original post

5 REPLIES 5
ari14
Calcite | Level 5

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.

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

Peter_C
Rhodochrosite | Level 12

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;

SteveDenham
Jade | Level 19

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

Ksharp
Super User

Peter.C and Steve Denham

Yes. It would be more simple , but not exactly look like the output OP want.

Smiley Happy

Ksharp

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1245 views
  • 6 likes
  • 5 in conversation