Long time spss user. I want to see what the sas equivalent is for this.
do if (x eq 1 and y eq 3).
compute a=2.
compute b=3.
compute c=7.
else if (x eq 2 and y eq 4).
compute a=1.
compute b=0.
compute c=4.
else.
compute a=4.
compute b=5.
compute c=9.
end if.
or do if have to do this three times, subbing in b and c for a?
if (x eq 1 and y eq 3) then compute a=2;
else if (x eq 2 and y eq 4) then compute a=1;
else then compute a=4; /* this line may not be correct */;
Thanks, Gene Maguin
@emaguin wrote:
Long time spss user. I want to see what the sas equivalent is for this.
do if (x eq 1 and y eq 3).
compute a=2.
compute b=3.
compute c=7.
else if (x eq 2 and y eq 4).
compute a=1.
compute b=0.
compute c=4.
else.
compute a=4.
compute b=5.
compute c=9.
end if.
or do if have to do this three times, subbing in b and c for a?
if (x eq 1 and y eq 3) then compute a=2;
else if (x eq 2 and y eq 4) then compute a=1;
else then compute a=4; /* this line may not be correct */;
Thanks, Gene Maguin
if (x eq 1 and y eq 3) then do; a=2; b=3; c=7; end; else if (x eq 2 and y eq 4) then do; a=1; b=0; c=4; end; else do; a=4; b=5; c=9; end ;
Please post code or log entries into a code box opened using the forum's {I} icon to preserve formatting and to prevent the forum from inserting additional new line characters.
data foo;
x=1;
y=3;
if (x eq 1 and y eq 3) then
do;
a=2;
b=3;
c=7;
end;
else if (x eq 2 and y eq 4) then
do;
a=1;
b=0;
c=4;
end;
else
do;
a=4;
b=5;
c=9;
end;
run;
I don't know about SPSS, by SAS syntax is fully described and explained in the documentation. You could start here, for example:
If a SELECT-WHEN (or CASE-WHEN in SQL) is more in line with your mental model, you can use SELECT-WHEN-OTHERWISE.
data in;
x=1; y=3;
output;
x=2; y=4;
output;
x=0; y=0;
output;
run;
data foo;
set in;
select;
when (x eq 1 and y eq 3)
do;
a=2; b=3; c=7;
end;
when (x eq 2 and y eq 4)
do;
a=1; b=0; c=4;
end;
otherwise
do;
a=4; b=5; c=9;
end;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.