Here is a way
Data new;
Input id Stat $ ;
datalines;
01 yes
02 yes
03 yes
04 yes
;
data want;
set new;
length result $ 10;
if stat='yes' then do result='High', 'Medium', 'Low';
output;
end;
drop Stat;
run;
Result:
Id Result 1 High 1 Medium 1 Low 2 High 2 Medium 2 Low 3 High 3 Medium 3 Low 4 High 4 Medium 4 Low
Here is a way
Data new;
Input id Stat $ ;
datalines;
01 yes
02 yes
03 yes
04 yes
;
data want;
set new;
length result $ 10;
if stat='yes' then do result='High', 'Medium', 'Low';
output;
end;
drop Stat;
run;
Result:
Id Result 1 High 1 Medium 1 Low 2 High 2 Medium 2 Low 3 High 3 Medium 3 Low 4 High 4 Medium 4 Low
This is a more novice approach but does it:
data result_table;
input stat $ result $;
datalines;
yes High
yes Medium
yes Low
;
proc sql;
create table want as
select t1.id, t2.result
from new t1 left join result_table t2 on t1.Stat=t2.Stat
order by t1.id, t2.result
;
quit;
What logic determines when to add 3 or 4 rows?
Anytime 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.