BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

How do I do I code the following SPSS code in SAS?

 

IF  (i3=0 | i3_1=2) i3_unmet=0.

EXECUTE.

 

IF  (i3_1=0 | i3_1=1) i3_unmet=1.

EXECUTE.

 

Part 1 of this code says if variable i3 is marked as not needed OR variable i3_1 is marked as “fully met” then your new variable i3_unmet is 0. 

Part 2 of this code says if variable i3_1 is marked as “not met” OR i3_1 is marked as partially met then your new variable i3_unmet is 1.

1 REPLY 1
Tom
Super User Tom
Super User

Looks like a normal IF THEN statement.  SAS does support using | and & as substitutes of AND and OR, but I can never remember which is which so it is probably better use the human readable keywords instead.

 

And IF statement would need to be part of a DATA step.  So if you have a dataset named HAVE that has the I3 and I3_1 variables then you could use a step like this to make a dataset named WANT that adds the I3_UNMET variable.

data want;
  set have;
  IF  (i3=0  or i3_1=2) then i3_unmet=0 ;
  IF  (i3_1=0  or  i3_1=1) then i3_unmet=1 ;
run;

For other combinations of values of i3 and i3_1 (such as when i3=1 or when i3_1=4) the value of I3_UNMET will not be set.

So if it already exists in the HAVE dataset the value for those observations will be unchanged.

And if it was not in the HAVE dataset then the value will be missing.

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!

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
  • 1 reply
  • 452 views
  • 2 likes
  • 2 in conversation