BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

I need to a create a new variable in a dataset from two datasets.

The number in  indi (dataset1) variable must match with  pid (dataset2) variable value and then the CMINAE should be concatenation of AE||#||PID||TERM.
How to extract the number from indi variable. The indi variable values are different lengths. Please help.

 

dataset1

ID                            indi
1                    Any EVENT, SPECIFY*-AE1
2                    Among EVENT, SPECIFY*-AE2

 


dataset2
id                                 term                              pid
1                            TOOTHACHE                       1
1                            HEADACHE                          2
2                            SINUSITIS                            1
2                            INFECTION                          2

 

OUTPUT NEEDED.

 

DATASET3;


ID                                   indi                                                                CMINAE
1                       Any EVENT, SPECIFY*-AE1                                  AE#1 TOOTHACHE
2                        Any EVENT, SPECIFY*-AE2                                 AE#2 INFECTION

 

1 REPLY 1
Patrick
Opal | Level 21

Below some options:

data have;
infile datalines dsd;
input ID indi $50.;
/* simple way if you can be sure that there is only one number in the string */
want1=input(compress(indi,,'kd'),?? best32.);

/* option 2: use -AE as token */
want2=input(substr(indi,find(indi,'-AE','i')+3),?? best32.);

/* or with a RegEx if the pattern is a bit more complicated*/
retain _rxID;
if _n_=1 then _rxID=prxparse('/-AE(\d+)/oi');
if prxmatch(_rxID, indi) then
do;
want3=input(prxposn(_rxID, 1, indi),?? best32.);
end;

datalines;
1,Any EVENT, SPECIFY*-AE1
2,Among EVENT, SPECIFY*-AE2
2,Among EVENT, SPECIFY*-AE34and something else 77
;
run;

 

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
  • 1094 views
  • 1 like
  • 2 in conversation