BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12
I have the data as follows and I need to convert per the desired output. If the claim is having identifier as 1 and 4 then I need to convert it to 0 which means converting duplicate claim into distinct claim.

Input data:

Claim identifier
001 1
001 4

Desired output:

Claim Identifier
001 0
1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

Here is a datastep solution:

data have;
input claim $ id;
cards;
001 1
001 2 
001 4
002 1
002 3 
002 5
;run;

data want;
  set 
    have(where=(id not in(1,4)))
    have(where=(id=1) in=in1)
    have(where=(id=4) in=in4)
    ;
  by claim;
  if in1 and not last.claim then
    id=0;
  if in4 and lag(id)=0 then
    delete;
run;

You may want to sort by claim and id afterwards, as the zeros, ones and fours are now last in the output.

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

data have;
input claim $ id;
cards;
001 1 
001 4
;

proc sql;
create table want as
select distinct claim, id not in (1,4) as id
from have
having id=0;
quit;
Babloo
Rhodochrosite | Level 12
Thanks. Any other alternate way using data step?
s_lassen
Meteorite | Level 14

Here is a datastep solution:

data have;
input claim $ id;
cards;
001 1
001 2 
001 4
002 1
002 3 
002 5
;run;

data want;
  set 
    have(where=(id not in(1,4)))
    have(where=(id=1) in=in1)
    have(where=(id=4) in=in4)
    ;
  by claim;
  if in1 and not last.claim then
    id=0;
  if in4 and lag(id)=0 then
    delete;
run;

You may want to sort by claim and id afterwards, as the zeros, ones and fours are now last in the output.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1050 views
  • 0 likes
  • 3 in conversation