BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
twildone
Pyrite | Level 9

Hi....I am trying to create the variable Final from the Decision variable. For each ID and Color group, if there is 'Yes' in the group, then Final is 'Yes' for the last row in the group and all other entries for Final is 'No'. Any suggestions on the best way to do this...Thanks

data Have;
    format ID best12. Color $char6. Part $char1. Decision $char3. Final $char3.;
	input ID : best32. Color : $char6. Part : $char1. Decision : $char3. Final : $char3.;
cards;
1 Yellow A Yes No
1 Yellow B No No
1 Yellow C No Yes
2 Blue A No No
2 Blue B Yes No
2 Blue C No Yes
3 Red A No No
3 Red B No No
3 Red C Yes Yes
4 Orange A Yes No
4 Orange B No Yes
5 Green B No No
5 Green C Yes Yes
6 Red A No No
6 Red C No No
;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by id color;
    length final $ 3;
    retain flag;
    if first.color then flag=0;
    if decision='Yes' then flag=1;
    if not last.color or (last.color and flag=0) then final='No';
    else if last.color and flag=1 then final='Yes';
    drop flag;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by id color;
    length final $ 3;
    retain flag;
    if first.color then flag=0;
    if decision='Yes' then flag=1;
    if not last.color or (last.color and flag=0) then final='No';
    else if last.color and flag=1 then final='Yes';
    drop flag;
run;
--
Paige Miller
twildone
Pyrite | Level 9
Thanks Paige!!!

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
  • 2 replies
  • 762 views
  • 0 likes
  • 2 in conversation