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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1895 views
  • 6 likes
  • 3 in conversation