BookmarkSubscribeRSS Feed
jmguzman
Fluorite | Level 6

Hello SAS Community,

 

I want to create a new version of an existing variable that only includes the scores of that existing variable if they correspond to a specific score on another variable. I'm not sure if that makes sense - I've only been using SAS for a month or two. The "str_e2_sq" variable is the severity rating (1 - 4) of a particular stressful life event and the "foc_e2" variable is the rating (1 - 4) of the focus of that event (self, joint, other, pet/possession). So, I'm trying to create variable of severity ratings by the focus of the stressful life event.

 

This the code I thought would work:

 

Data = DHEASLES.sles_master;
set = DHEASLES.sles_master;
IF foc_e2 = 1 AND str_e2_sq GE . then str_e2_sq_new = str_e2_sq;
ELSE str_e2_sq_new = .;
run;

 

I got the following errors:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69
70 Data = DHEASLES.sles_master;
____
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
71 set = DHEASLES.sles_master;
___
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
72 IF foc_e2 = 1 AND str_e2_sq GE . then str_e2_sq_new = str_e2_sq;
__
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
73 ELSE str_e2_sq_new = .;
____
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
74 run;
75
76 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
86
 
Thank you so much for the help!

Best,
Joe
2 REPLIES 2
Tom
Super User Tom
Super User

The DATA and SET statements do not use equal signs.

By adding them you have created what looks like assignment statements instead to create variables named DATA and SET.

jmguzman
Fluorite | Level 6

 

Man, I'm not even sure why I put those equal signs there when I've never done that before. I guess that's what happens when you think that running code on a weekend night instead of relaxing is a good idea.

 

Thank you so much!

 

Best,

Joe

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 485 views
  • 3 likes
  • 2 in conversation