BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasuser123123
Quartz | Level 8
Data new;
Input id Stat $ ;
datalines;
01 yes
02 yes
03 yes
04 yes
;

Now If id=yes ,I want to add three values(high, medium,low) per subject .
Output should like...

Id result
01 High
01 medium
01 low
02 high
02 medium
02 low

Could you please help me how to do this one


Thank you!
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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

View solution in original post

7 REPLIES 7
sasuser123123
Quartz | Level 8
If stat=yes ..not I'd
Sorry for the mistake
PeterClemmensen
Tourmaline | Level 20

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
sustagens
Pyrite | Level 9

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;
sasuser123123
Quartz | Level 8
@PeterClemmensen thank you so much for your help.
It's perfectly fine.
But how to do if we want to add 3 values to one subject and 4 values to another subject.
PeterClemmensen
Tourmaline | Level 20

What logic determines when to add 3 or 4 rows?

sasuser123123
Quartz | Level 8
Oh okay .. exactly. I got your point , it depends on logic or the condition.

Thank you so much !!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 7 replies
  • 1386 views
  • 3 likes
  • 3 in conversation