BookmarkSubscribeRSS Feed
anuragchoubey
Calcite | Level 5

Hi, Fellow community members !!

 

I am trying to vlookup of two data set and update strings for example:

 

I am trying to compare the column  "Old trait id" to the dataset B for matches and update the matches in Dataset B by appending "New trait id" with string "OR".

 

Dataset A

NEW TRAIT IDOLD TRAIT ID
16070843T74160T
16070844T16981T
16070847T79556T

Dataset B

segmentRule
(74160T OR 16981T) AND (79556T)

Output 

(74160T OR 16070843T OR 16981T OR 16070844T) AND (79556T OR 16070847T)
1 REPLY 1
ChrisNZ
Tourmaline | Level 20

This works:

data  A(index=(OLD_TRAIT_ID));
 input NEW_TRAIT_ID $10. OLD_TRAIT_ID $;
cards;
16070843T	74160T
16070844T	16981T
16070847T	79556T
run;
data B;
  SEGMENT_RULE='(74160T OR 16981T) AND (79556T)';
run;
data WANT;
  set B;
  length NEW_RULE $200;
  NEW_RULE=SEGMENT_RULE;
  do I=1 to countw(SEGMENT_RULE,' ()');
    OLD_TRAIT_ID=scan(SEGMENT_RULE,I,' ()');
    if length(OLD_TRAIT_ID)<6 then continue;
    set A key=OLD_TRAIT_ID;   
    if _IORC_ then do;
      _ERROR_=0;
      continue;
    end;      
    NEW_RULE=tranwrd(NEW_RULE,trim(OLD_TRAIT_ID),catx(' OR ',OLD_TRAIT_ID,NEW_TRAIT_ID));    
  end;
run;
proc print noobs; 
  var NEW_RULE;
run;
NEW_RULE
(74160T OR 16070843T OR 16981T OR 16070844T ) AND (79556T OR 16070847T )

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 397 views
  • 0 likes
  • 2 in conversation