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!!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 375 views
  • 0 likes
  • 2 in conversation