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

Hello Everyone,

 

The Have dataset is sorted by ID and Ranks. For each group, by ID, I am trying to pick the first observation for which the difference is less than equal to 12. For example, for ID 0001, the Want dataset has the secon observation. Would really appreciate if anyone could help me out.

 

Thanks

Have   Want  
IDRankDiff IDRankDiff
0001220    
000138 000138
0001444    
0001538    
0002218    
000243 000243
000256    
00021230    
0003111 0003111
0003223    
0003347    
00035

2

    
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

 

Create a flag that indicates if you've found the record. So your logic becomes less than or equal to 12 AND flag is not set.

 

data want;
set have;
by id;
retain flag;
if first.id then flag=0;

if diff<=12 and flag=0 then do;
output;
flag=1;
end;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

 

Create a flag that indicates if you've found the record. So your logic becomes less than or equal to 12 AND flag is not set.

 

data want;
set have;
by id;
retain flag;
if first.id then flag=0;

if diff<=12 and flag=0 then do;
output;
flag=1;
end;

run;
sai_ch
Obsidian | Level 7

Thanks Reeza for the solution.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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