BookmarkSubscribeRSS Feed
Moses_Lutaaya
Calcite | Level 5

I am new to  SAS and learning with videos. 

I written this code but SAS returns a mistake. what is the problem here.

 

CODE

proc print data = sashelp.heart;
set sashelp.heart;
where chol Status = "High";
run;

 

Log message

ERROR: Syntax error while parsing WHERE clause.
ERROR 180-322: Statement is not valid or it is used out of proper order.
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.
76 run;
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
 
77
78 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
90
3 REPLIES 3
Shmuel
Garnet | Level 18

You are mixing two tools:

1) Data Step:

data <output_dat_set>;
   set <input_data_set>;
         /* any more sas statements and functions */
run;

2) Executing a procedure like PROC PRINT:

proc print data=<input_data_set> <more options>;
   var <list order of variables to print >;
   /* more statement for proc print>;
run;

3) Look for sas documentation of each procedure or statement keyword or function.

 

Good Luck.

Kurt_Bremser
Super User

Here's the most important link for your future SAS life:

SAS 9.4 Programming Documentation 

There you can find (among a galaxy of other things) all procedures, and the statements that are valid in each.

Some DATA step statements (like WHERE) can also be used in PROC steps, but SET is not among them. SET is data step only. And not necessary here, as the input dataset for PROC PRINT is already defined by the DATA= option.

Cynthia_sas
SAS Super FREQ

Hi:

  In addition to the other excellent suggestions, my suggestion is that you run a PROC CONTENTS to make sure you are spelling the variable names correctly when you use them. For example:

Cynthia_sas_0-1604798935231.png

Notice that variables like Weight_Status and Chol_Status have underscores in the variable name (not spaces).

Cynthia

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 470 views
  • 0 likes
  • 4 in conversation