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

Hello,

 

I am not new to SAS but I am by no means an expert.  I am working with a new dataset and trying to creating some new variables using the "if-then" statement.  However, when I do this, I keep getting the same error with each step.  I can't figure out what I am doing wrong -- I haven't had this problem before using these steps.  Please help! 

 

Here is the code I am using:

 

data=work.allmdsurgeons1;
set=work.allmdsurgeons;
if residency = 0 then res_type = 0;
else res_type= 1;
run;

 

In the log after I run this, under each line I get "ERROR 180-322: Statement is not valid or it is used out of proper order."  I don't know why this is happening for the data step and the set step.  If someone could help I would really appreciate it!  Thanks!

 
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Your IF/THEN statements are fine.  However, DATA and SET statements don't use an equal sign.  Change the equal sign to a blank character for those two statements.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Your IF/THEN statements are fine.  However, DATA and SET statements don't use an equal sign.  Change the equal sign to a blank character for those two statements.

feltonjm
Calcite | Level 5

Wow, I feel so stupid. Thanks for the help!

ballardw
Super User

With errors it is usually a good idea to paste the code with error messages. To preserve the formatting of the error messages paste them into a code box opened with the {I} menu icon on in the header of the message box on the forum. Such as:

494  data=work.allmdsurgeons1;
     ----
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

495  set=work.allmdsurgeons;
     ---
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

496  if residency = 0 then res_type = 0;
     --
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

497  else res_type= 1;
     ----
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

498  run;

Which will show us which specific line and where SAS detected the error.

 

Since the first instance is with data you might look at example code (almost anywhere) to remember the data step does not use =, or Set.

The others are because the statements are only valid in a data step and SAS has not recognized the valid start of a data step.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1086 views
  • 0 likes
  • 3 in conversation