BookmarkSubscribeRSS Feed
luvscandy27
Quartz | Level 8

Hello Everyone, 

 

I was hoping someone could help me understand where I am going wrong when using proc means

with multiple variables. I am using the sashelp.heart dataset. When I use the code below

with one variable the code works fine.

proc means data = heart (where=(weight GE 140)) noprint;
var weight;
by sex;
output out = out (drop=_type_ _freq_);
run;

However, when I try to use the code with multiple variables (code below) I get an error message.  I have

tried adding a comma between the variables however, I still get the error. Could someone assist me with this please?

 

proc means data = heart (where=(weight cholesterol GE 140)) noprint;
var weight cholesterol;
by sex;
output out = out (drop=_type_ _freq_);
run;

The error message is: 

ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT, LE,
LT, NE, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
4 REPLIES 4
Tom
Super User Tom
Super User

This is not valid code:

where=(weight cholesterol GE 140)

What is the condition you are actually trying to test?

luvscandy27
Quartz | Level 8
I would like to get all the observations with weight, systolic, and
cholesterol greater than 140. I would like the count and mean for the three
variables.
ballardw
Super User

In

(weight cholesterol GE 140)

what condition are you placing on weight? There is none. Plus when you have two or more variables you need to indicate the relationship between two comparisons such as

 

weight ge 100 and cholesterol ge 140  => records with individuals having weight ge 100 AND cholesterol ge 160

or perhaps

 

weight ge 100 OR cholesterol ge 140

 

If you meant to have the same range for both variables then you need to list both explicitly.

A variable with no condition will be treated as true if the value is not 0 or missing. But again if multiple variables are used you need to specify the relationship between the two (or more variables).

 

When showing us an error message you should should copy the entire proc or datastep involved and paste into a code box opened using the </> or "running man" icon on the forum.

If you look at the way it appeared in the log, which should be similar to the following then you see that there were a number of underscore characters under the word cholesterol. That means the error of an expected character or operation is before that word. In this case likely was an "AND" or "OR" for which comparison you wanted between the two variables.

108  proc means data = sashelp.heart (where=(weight cholesterol GE 140)) noprint;
                                                    -----------
                                                    22
                                                    76
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=,
              <>, =, >, >=, AND, EQ, GE, GT, LE, LT, NE, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
109     var weight cholesterol;
110     by sex;
111     output out = out (drop=_type_ _freq_);
112  run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.OUT may be incomplete.  When this step was stopped there were 0
         observations and 0 variables.

PaigeMiller
Diamond | Level 26
proc means data = heart (where=(weight ge 140 and cholesterol GE 140)) noprint;

Naturally the above syntax is an example. You should modify it to whatever the proper condition is for your problem.

 
 
 
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 7951 views
  • 0 likes
  • 4 in conversation