I am learning about proc means from the book Learning SAS by Example. Unfortunately, even though my answer seems to be very similar to a similar one shown in the book (for a similar problem), I am getting all kinds of errors. I am not sure why. I have looked thoroughly but am not sure what fixes to make. Maybe someone can help. Thanks.
Below is the code:
-------------------------------------
Libname Learn '/folders/myfolders/Learn' ;
Libname Myformat '/folders/myfolders/sasuser.v94' ;
proc means data=learn.college maxdec=2 chartype ;
class Gender SchoolSize ;
var ClassRank GPA ;
output out = summary
mean =
n =
max =
min = /autoname ;
run ;
Data Grand_College(drop = Gender SchoolSize) ;
byGender(drop = SchoolSize) ;
bySchoolSize(drop = Gender) ;
cellmeans ;
set learn.college ;
drop _type ;
rename _freq_ = Number ;
if _type_ = '00' then output grand ;
else if _type_ = '01' then output byGender ;
else if _type_ = '10' then output bySchoolSize ;
else if _type_ = '11' then output cellmeans ;
run ;
-------------------------------------------------
Below here is the Log
---------------------------------------------
While there may be more errors once this is cleared up, this one is easy. You are using your original data set as the input to your final DATA step. That doesn't contain the right information. Your SET statement should refer to the output data set from PROC MEANS:
set summary;
You have inserted extra semi-colons into the middle of your DATA statement. This is making the dataset options look like array index specifications. Just remove the extra semi-colons. I find that it helps when I have a single statement that takes multiple lines if I put the terminating semi-colon on a new line. Like you would for DO;/END; block.
data Grand_College(drop = Gender SchoolSize)
byGender(drop = SchoolSize)
bySchoolSize(drop = Gender)
cellmeans
;
set learn.college ;
drop _type ;
rename _freq_ = Number ;
if _type_ = '00' then output grand ;
else if _type_ = '01' then output byGender ;
else if _type_ = '10' then output bySchoolSize ;
else if _type_ = '11' then output cellmeans ;
run ;
Thanks. That does take care of the error messages. That is very helpful.
Ultimately, I am trying to get summaries for three groups:
1. All
2. by Gender
3. By SchoolSize.
Unfortunately, the log I am getting is showing 0 observations for all of these: Is there something else I am missing? Tx!
----------------------------
While there may be more errors once this is cleared up, this one is easy. You are using your original data set as the input to your final DATA step. That doesn't contain the right information. Your SET statement should refer to the output data set from PROC MEANS:
set summary;
Or perhaps
proc tabulate data=learn.college ; class Gender SchoolSize ; var ClassRank GPA ; tables Gender SchoolSize Gender*SchoolSize, (ClassRank GPA)*(mean n max min) ; run;
or
proc tabulate data=learn.college ; class Gender SchoolSize ; var ClassRank GPA ; tables Gender , (ClassRank GPA)*(mean n max min) ; tables SchoolSize, (ClassRank GPA)*(mean n max min) ; tables all, (ClassRank GPA)*(mean n max min) ; run;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.