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

Hi, I want to assign category to the ID 1234 if age < =24. In the below example I have 3 rows in this ID which satisfies the condition.

But I want the category to be assigned to the max age (only) available below 24 months, In this case it is 12 months. 

Condition for version is either 0 or 1. 

 

Can't figure out how to get this done. Please advise. 

 

IDAge in monthsVersionCategory
12340.0328542090Severe
123420Severe
1234120Severe

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

I'd use a double DO loop:

proc sort data=have;
by id age;
run;

data want;
do until (last.id);
  set have;
  by id;
  if age le 24 then maxage = max(maxage,age);
end;
do until (last.id);
  set have;
  by id;
  category = (maxage = age);
  output;
end;
drop maxage;
run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

I'd use a double DO loop:

proc sort data=have;
by id age;
run;

data want;
do until (last.id);
  set have;
  by id;
  if age le 24 then maxage = max(maxage,age);
end;
do until (last.id);
  set have;
  by id;
  category = (maxage = age);
  output;
end;
drop maxage;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 749 views
  • 0 likes
  • 2 in conversation