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!
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.
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.
Wow, I feel so stupid. Thanks for the help!
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.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.