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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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