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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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