BookmarkSubscribeRSS Feed
kelly6984
Fluorite | Level 6

Hey guys,

I have a variable titled "Medications" that contains all of the medications that a individual has taken. I used an "if then" statement to separate the different medications by type (i.e. HIV meds, Cholesterol meds, Diabetes meds), but it didn't recognize all of the medications. Each medication was separated by a comma, so I used the compress function to remove the comma. Now the medications are separated by a blank. I tried the "if then" statement again and it still doesn't recognize them.

For instance, one patient's values for the medication variable is "Atripla Lisinopril Sustiva Pravachol Combivir Zetia." Atripla, Zetia and Combivir are HIV meds, while Lisinopril is a Blood Pressure med, and Pravachol is a cholesterol medication. The SAS code that I'm using does not pick up the fact that I have any HIV meds, Cholesterol or BP meds. Any suggestions??

Thanks,

Kelly

3 REPLIES 3
robby_beum
Quartz | Level 8

Try the STRIP function to remove leading and trailing blanks:

if STRIP(medications) IN( ...) then ...;

else if STRIP(medications) IN( ...) then ...;

else if STRIP(medications) IN( ...) then ...;

else if STRIP(medications) IN( ...) then ...;

else if STRIP(medications) IN( ...) then ...;

else...;


Actually, after re-reading,  I think you want the INDEX function:

if INDEX(medications, "Atripla") >0 or INDEX(medications, "Zetia") >0 or INDEX(medications, "Combivir") >0 THEN med = 'HIV';

else if INDEX(medications, "Lisinopril") >0 THEN med = 'Blood Pressure';

else if INDEX(medications, "Pravachol") >0 THEN med = 'Cholesterol';

Or...if your trying to just flag them on each detail line...

if INDEX(medications, "Atripla") >0 or INDEX(medications, "Zetia") >0 or INDEX(medications, "Combivir") >0 THEN hiv_med = 1;

else if INDEX(medications, "Lisinopril") >0 THEN bp_med = 1;

else if INDEX(medications, "Pravachol") >0 THEN chol_med = 1;

kelly6984
Fluorite | Level 6

Thanks so much! The Index function worked!!!

Astounding
PROC Star

kelly,

While you haven't shown your code, the main reason this type of data is difficult to count is because of variations in spelling (including variations in capitalization).  In your case, you also have to realize the COMPRESS does not replace the commas with blanks.  It removes the commas, and you might end up with two names running together without a blank between them.

Do you have any medications where the names are two words instead of one?  If so, it would be wise to leave the commas in place.  You could always move through the list in this way:

do _i_ = 1 by 1 until (scan(medications, _i_+1, ',') = ' ');

   next_medication = scan(medications, _i_, ',');

   ** add logic here to categorize next_medication;

end;

Good luck.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 530 views
  • 0 likes
  • 3 in conversation