BookmarkSubscribeRSS Feed
bg
Calcite | Level 5 bg
Calcite | Level 5

 

MED01      HTN  DM   MAIN01

HTN           0       0

DM            1       1

HTN            0      1

HTN            0      0

DM             0      1

I have a large database with information on medications taken by a few thousand people. I need to determine if a medication is a maintenance medication.

As an example above is a small snippet just looking at one medication for 5 people and a couple of disease conditions, HTN and DM

I need to compute the value of MAIN01...1 if a medication is a maintenance med and 0 if not

For example for the first observation, I look at the value of MED01 and I see that a HTN drug was used so  I need to check if person has HTN .  If HTN=1 then MAIN01=1 else MAIN01=0.

For the second observation, I look at the value of MED01 and see that I need to check if person has DM.  If DM=1 thenn MAIN01=1 else MAIN01=0

So the resulting data set would be

MED01      HTN  DM   MAIN01

HTN           0       0         0

DM            1       1         1

HTN            0      1         0

HTN            1      0         1

DM             0      1         1

Any suggestions as to how I could code this?

thanks!

Barbara

4 REPLIES 4
LarryWorley
Fluorite | Level 6

How about:

Main01 = ( med01 = 'HTN')*htn  or (med01 = 'DM')*dm ;

If logical expressions are not you cup of tea, you could also use if-then logic.


bg
Calcite | Level 5 bg
Calcite | Level 5

Thanks!

art297
Opal | Level 21

Assuming there is a discrepancy in the data you showed in your have and want examples (namely for the 4th record), then the following would be easy to implement for any number of drugs:

data have;

  input MED01  $    HTN  DM;

  cards;

HTN           0      0

DM            1      1

HTN           0      1

HTN           1      0

DM            0      1

;

data want;

  set have;

  array drugs htn--dm;

  do over drugs;

    if med01 eq vname(drugs) and drugs eq 1 then MAIN01=1;

  end;

  if missing(MAIN01) then MAIN01=0;

run;

bg
Calcite | Level 5 bg
Calcite | Level 5

Thanks!

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
  • 4 replies
  • 1363 views
  • 6 likes
  • 3 in conversation