SAS code -

Reply
Occasional Contributor
Posts: 15

SAS code -

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

Contributor
Posts: 72

Re: SAS code -

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;

Occasional Contributor
Posts: 15

Re: SAS code -

Thanks so much! The Index function worked!!!

Super User
Posts: 5,071

Re: SAS code -

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.

Ask a Question
Discussion stats
  • 3 replies
  • 231 views
  • 0 likes
  • 3 in conversation