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-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!

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.

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
  • 3 replies
  • 863 views
  • 0 likes
  • 3 in conversation