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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1615 views
  • 6 likes
  • 3 in conversation