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 )

 

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
  • 1 reply
  • 783 views
  • 0 likes
  • 2 in conversation