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

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

---------------------------------------------

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 /* Chapter 16
63 Problem 16.7*/
64
65 Libname Learn '/folders/myfolders/Learn' ;
NOTE: Libref LEARN refers to the same physical library as LEARN2.
NOTE: Libref LEARN was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/Learn
66 Libname Myformat '/folders/myfolders/sasuser.v94' ;
NOTE: Libref MYFORMAT refers to the same physical library as MYFORMT2.
NOTE: Libref MYFORMAT was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/sasuser.v94
67
68
69 proc means data=learn.college maxdec=2 chartype ;
70 class Gender SchoolSize ;
71 var ClassRank GPA ;
72 output out = summary
73 mean =
74 n =
75 max =
76 min = /autoname ;
77 run ;
 
NOTE: There were 100 observations read from the data set LEARN.COLLEGE.
NOTE: The data set WORK.SUMMARY has 12 observations and 12 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.18 seconds
cpu time 0.18 seconds
 
77 !
 
78
79 Data Grand_College(drop = Gender SchoolSize) ;
80 byGender(drop = SchoolSize) ;
_
22
76
ERROR: Undeclared array referenced: byGender.
81 bySchoolSize(drop = Gender) ;
_
22
76
ERROR: Undeclared array referenced: bySchoolSize.
82 cellmeans ;
_________
180
ERROR 22-322: Syntax error, expecting one of the following: +, =.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
83 set learn.college ;
ERROR: Variable Gender has been defined as both character and numeric.
ERROR: Variable SchoolSize has been defined as both character and numeric.
84 drop _type ;
85 rename _freq_ = Number ;
86 if _type_ = '00' then output grand ;
_____
455
87 else if _type_ = '01' then output byGender ;
________
455
88 else if _type_ = '10' then output bySchoolSize ;
____________
455
89 else if _type_ = '11' then output cellmeans ;
_________
455
ERROR 455-185: Data set was not specified on the DATA statement.
 
90 run ;
 
WARNING: The variable _type in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable _freq_ in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.GRAND_COLLEGE may be incomplete. When this step was stopped there were 0 observations and 6 variables.
WARNING: Data set WORK.GRAND_COLLEGE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
 
90 !
 
91
92
93 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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 ;     

 

 

ManitobaMoose
Quartz | Level 8

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!

----------------------------

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 /* Chapter 16
63 Problem 16.7*/
64
65 Libname Learn '/folders/myfolders/Learn' ;
NOTE: Libref LEARN refers to the same physical library as LEARN2.
NOTE: Libref LEARN was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/Learn
66 Libname Myformat '/folders/myfolders/sasuser.v94' ;
NOTE: Libref MYFORMAT refers to the same physical library as MYFORMT2.
NOTE: Libref MYFORMAT was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/sasuser.v94
67
68
69 proc means data=learn.college maxdec=2 chartype ;
70 class Gender SchoolSize ;
71 var ClassRank GPA ;
72 output out = summary
73 mean =
74 n =
75 max =
76 min = /autoname ;
77 run ;
 
NOTE: There were 100 observations read from the data set LEARN.COLLEGE.
NOTE: The data set WORK.SUMMARY has 12 observations and 12 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.17 seconds
cpu time 0.17 seconds
 
77 !
 
78
79 Data Grand_College(drop = Gender SchoolSize)
80 byGender(drop = SchoolSize)
81 bySchoolSize(drop = Gender)
82 cellmeans ;
83 set learn.college ;
84 drop _type_ ;
85 /*rename _freq_ = Number ; */
86 if _type_ = '00' then output grand_college ;
87 else if _type_ = '01' then output byGender ;
88 else if _type_ = '10' then output bySchoolSize ;
89 else if _type_ = '11' then output cellmeans ;
90 run ;
 
NOTE: Format $GENDER was not found or could not be loaded.
NOTE: Format $SIZE was not found or could not be loaded.
NOTE: Format $YESNO was not found or could not be loaded.
NOTE: Variable _type_ is uninitialized.
NOTE: There were 100 observations read from the data set LEARN.COLLEGE.
NOTE: The data set WORK.GRAND_COLLEGE has 0 observations and 4 variables.
NOTE: The data set WORK.BYGENDER has 0 observations and 5 variables.
NOTE: The data set WORK.BYSCHOOLSIZE has 0 observations and 5 variables.
NOTE: The data set WORK.CELLMEANS has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.02 seconds
 
90 !
 
91
92
93 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 

 

 

Astounding
PROC Star

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;

ballardw
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 5235 views
  • 1 like
  • 4 in conversation