BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta1
Obsidian | Level 7

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

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

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

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

lillymaginta1
Obsidian | Level 7

Thank you! 

Ksharp
Super User

data want;
set have;
if upcase(drugname)=:'ORAL' then indicator=1;
else indicator=0;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 592 views
  • 2 likes
  • 3 in conversation