BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bknitch
Quartz | Level 8
data have;
input MEMB_ID DUPFLAG MEMBER_LOB $;
datalines;
1233 0 JR 1234 1 WR 1234 1 WD 1235 0 JD 1236 1 UR 1236 1 UD 1237 1 JD 1237 1 JR 1238 0 WD
1239 0 WR ; data _null_; set HAVE; if _n_=1 then do; declare hash h(dataset: 'HAVE', multidata: 'y',ordered:'y'); h.definekey('MEMB_ID'); h.definedata('MEMB_ID','DUPFLAG','MEMBER_LOB'); h.definedone(); end; set HAVE(where=(DUPFLAG=1 and MEMBER_LOB in ('JR','UR','WR'))) end=last; if h.check()=0 then h.remove(); if last then h.output(dataset:'TEST1'); run;

 

I want to delete records in a large data set that contain multiple Member_LOB's. I've built a dup flag to identify this population, i want to remove any memb_id where a dupflag=1 and LOB ends in R but retain the members other LOB.

 

For example, ID 1234 i want to remove the record where LOB=WR but keep record where LOB=WD. I know my dupflag is causing my function to delete the records i want to retain. any help would be appreciated 

 

These are my results 

MEMB_IDDUPFLAGMEMBER_LOB
12330JR
12350JD
12380WD
12320JR
12390WR


What i want is this. 

MEMB_IDDUPFLAGMEMBER_LOB
12330JR
12341WD
12350JD
12361UD
12371JD
12380WD
12390WR

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Thank you @bknitch  Please see if this helps

 

data have;
input MEMB_ID DUPFLAG MEMBER_LOB $;
datalines;
1233 0 JR
1234 1 WR
1234 1 WD 
1235 0 JD
1236 1 UR
1236 1 UD
1237 1 JD
1237 1 JR
1238 0 WD
1239 0 WR
;
/*_n_=char(upcase(MEMBER_LOB),length(MEMBER_LOB))='R'; This checks if the END letter */
/*of MEMBER_LOB is "R"*/
data want;
 do until(last.MEMB_ID);
  set have;
  by memb_id;
  _n_=char(upcase(MEMBER_LOB),length(MEMBER_LOB))='R';
  if _n_ and DUPFLAG then continue;
  output;
 end;
run;
MEMB_ID DUPFLAG MEMBER_LOB
1233 0 JR
1234 1 WD
1235 0 JD
1236 1 UD
1237 1 JD
1238 0 WD
1239 0 WR

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Hi @bknitch  The description " i want to remove any memb_id where a dupflag=1 and LOB ends in R." is misleading to what's in your sample input/output.  For example, why 1233 0 JR was dropped?  Plus, I am not certain you need HASH approach albeit up-to you. Kindly review

bknitch
Quartz | Level 8

I must have forgot to post it in my description, it was not removed. It retained it in my output. 

novinosrin
Tourmaline | Level 20

Okay no worries, Can you please edit the original post to the correct representation? This can help avoid any confusion

bknitch
Quartz | Level 8

Just edited, my apologies. 

novinosrin
Tourmaline | Level 20

Thank you @bknitch  Please see if this helps

 

data have;
input MEMB_ID DUPFLAG MEMBER_LOB $;
datalines;
1233 0 JR
1234 1 WR
1234 1 WD 
1235 0 JD
1236 1 UR
1236 1 UD
1237 1 JD
1237 1 JR
1238 0 WD
1239 0 WR
;
/*_n_=char(upcase(MEMBER_LOB),length(MEMBER_LOB))='R'; This checks if the END letter */
/*of MEMBER_LOB is "R"*/
data want;
 do until(last.MEMB_ID);
  set have;
  by memb_id;
  _n_=char(upcase(MEMBER_LOB),length(MEMBER_LOB))='R';
  if _n_ and DUPFLAG then continue;
  output;
 end;
run;
MEMB_ID DUPFLAG MEMBER_LOB
1233 0 JR
1234 1 WD
1235 0 JD
1236 1 UD
1237 1 JD
1238 0 WD
1239 0 WR
bknitch
Quartz | Level 8
Awesome! That worked perfectly, thank you very much!

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

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
  • 6 replies
  • 1493 views
  • 1 like
  • 2 in conversation