BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

I have data set like this with more than 50 variables

Doxycycline_100MG_PO_BID_X_07ACYCLOVIR_400MG_TID_X_7_DAYSMETRONIDAZOLE_500MG_POBID_X14D
DOXYCYCLINE 100MG PO BID X 07  
 ACYCLOVIR 400MG TID X 7 DAYSMETRONIDAZOLE 500MG POBID X14D
DOXYCYCLINE 100MG PO BID X 07 METRONIDAZOLE 500MG POBID X14D
   
 ACYCLOVIR 400MG TID X 7 DAYS 

I want to code these  as if METRONIDAZOLE_500MG_POBID_X14D="METRONIDAZOLE 500MG POBID X14D" then METRONIDAZOLE_500MG_POBID_X14D="1"; else METRONIDAZOLE_500MG_POBID_X14D="0";

 How can I do it at once?

 

4 REPLIES 4
Reeza
Super User
WHICHC()

metrodizale = whichc('XXXXXdlkfjdklfjdlkfd', <list of variables here>) > 0;
Dhana18
Obsidian | Level 7

Sorry I am not very clear of your code suggestion I used like this and it did not work.

data LANLYSIS.Clinic_MEDICATION_CODED;

set LANLYSIS.Clinic1_SYMPTOMS_CODED;

METRONIDAZOLE_500MG_POBID_X_7D =WHICHC('METRONIDAZOLE 500MG POBID X 7D' , CEFTRIAXONE_ROCEPHIN_250MG_IM='CEFTRIAXONE(ROCEPHIN)250MG IM') >'0';

run;

the result is metronidazole all coded 0 and nothing happened in CEFTRIAXONE_ROCEPHIN_250MG_IM.

Please help.

Thank you.

Dhana18
Obsidian | Level 7

it should only be two categories, if the response is present that should be coded "1" if the response is missing then that should be coded "0"

please help my life make my life easier. 

Reeza
Super User

@Dhana18 wrote:

 

please help my life make my life easier. 


Did you try reading the WHICHC() documentation? That's the fastest solution besides me just coding it for you.

 

Please re-read my answer, you didn't put the parameters in properly to the WHICHC() function. The first is the string you're looking for and the second is the variables that may contain that string. Then it returns the index of the variable if it's found or 0 if not found. So you can check if the return value is greater than 0 and it will get coded to a 0/1 automatically. Not sure why you put the 0 in quotes.

 

It's a single line solution to get your answer. If it doesn't work please post your code using the insert code button and the log indicating the error?

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
  • 4 replies
  • 562 views
  • 0 likes
  • 2 in conversation