data have;
infile cards ;
input ID drugname ;
cards;
001 sodium oral benzoate
002 oral sodium
003 oral potassium
004 oral Sodium
005 Sodium oral
;
hi everyone,
I am trying to extract records that start with the word "oral" only at the beginning.
output
001 0
002 1
003 1
004 1
005 0
Hello,
Your data step is not working ;-).
Here's the code you are after:
data have;
LENGTH drugname $ 20;
infile cards delimiter='|';
input ID $ drugname $ ;
cards;
001 |sodium oral benzoate
002 |oral sodium
003 |oral potassium
004 |oral Sodium
005 |Sodium oral
;
run;
data want;
set have;
if upcase(scan(drugname,1,' '))='ORAL' then indicator=1;
else indicator=0;
run;
/* end of program */
Koen
Hello,
Your data step is not working ;-).
Here's the code you are after:
data have;
LENGTH drugname $ 20;
infile cards delimiter='|';
input ID $ drugname $ ;
cards;
001 |sodium oral benzoate
002 |oral sodium
003 |oral potassium
004 |oral Sodium
005 |Sodium oral
;
run;
data want;
set have;
if upcase(scan(drugname,1,' '))='ORAL' then indicator=1;
else indicator=0;
run;
/* end of program */
Koen
Thank you!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: