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.

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!

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
  • 3 replies
  • 791 views
  • 0 likes
  • 3 in conversation