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

hey, I'm confused what's the problem with these codes. 

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

Is there anything wrong?😰

%let  T = "Temp_status";

%let  W = "Work_Status";

%let  C = "cough";

Data  Grocery2;

set  Grocery1;

if  &T = "missing"  or &C = "" then  &W = "DayOff" ;

else if  &T = "normal"  and &C = "N" then  &W = "Worked" ;

else  &W = "Sick" ;

run ;

proc freq data  = grocery2;

table  &T*&C*&W/list missing ;

run ;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please copy the entire data step or procedure when asking questions about notes, errors or warnings. Sometimes the "cause" is something before the place indicates an error such as a missing semicolon, matching quote or parentheses.

Copy the entire text from the LOG, open a text box on the forum using the </> icon and paste the text.

Many of the errors like 180-322 often place diagnostic characters in the text and pasting the result into the main message window gets the text reformatted so the diagnostics are in the wrong place.

 

Your use of &W is placing it in the position of a variable assigning a value. By default variable names cannot contain quote marks.

If &T and &C are also supposed to be variables do not place the value in quotes.

You have created lines of code like:

 

Data  Grocery2;
   set  Grocery1;
  if  "Temp_status"= "missing"  or "cough" = "" then  "Work_status" = "DayOff" ;
  else if  "Temp_status" = "normal"  and "cough" = "N" then   "Work_status" = "Worked" ;
  else   "Work_status" = "Sick" ;
run ;

Since this code compares the literal text value of "Temp_status" to "missing" or "normal" it is never true. Also "cough" is never true compared to "" or "N".

 

 

 

View solution in original post

1 REPLY 1
ballardw
Super User

Please copy the entire data step or procedure when asking questions about notes, errors or warnings. Sometimes the "cause" is something before the place indicates an error such as a missing semicolon, matching quote or parentheses.

Copy the entire text from the LOG, open a text box on the forum using the </> icon and paste the text.

Many of the errors like 180-322 often place diagnostic characters in the text and pasting the result into the main message window gets the text reformatted so the diagnostics are in the wrong place.

 

Your use of &W is placing it in the position of a variable assigning a value. By default variable names cannot contain quote marks.

If &T and &C are also supposed to be variables do not place the value in quotes.

You have created lines of code like:

 

Data  Grocery2;
   set  Grocery1;
  if  "Temp_status"= "missing"  or "cough" = "" then  "Work_status" = "DayOff" ;
  else if  "Temp_status" = "normal"  and "cough" = "N" then   "Work_status" = "Worked" ;
  else   "Work_status" = "Sick" ;
run ;

Since this code compares the literal text value of "Temp_status" to "missing" or "normal" it is never true. Also "cough" is never true compared to "" or "N".

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 970 views
  • 1 like
  • 2 in conversation