BookmarkSubscribeRSS Feed
Tpham
Quartz | Level 8

So I have a variable called cumlative dosage. I want to code a patient to see if they are above or the below the median dosage.

So when I run:

proc means data=temp n min max median;

     var avcumdos_6wper;

     run;

This is the following output

                                           N         Minimum         Maximum          Median

                                         ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

                                         184       1.1695906      10.4000000      4.0354701

                                         ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

So I want to calculate a flag variable around that mean.  where flag=. if avcumdos_6wper=.,  flag=1 if avcumdos_6wper <= median or flag=2 if avcumdos_6wper> median.

So I figure I can do this via sql, but i can't seem to get it to work. It just copies the variable. This is my code thus far:

proc sql;

create table temp1 as

select patientid, visit, avcumdos_6wper, median(avcumdos_6wper) as mv,

  case when avcumdos_6wper = .  then .

  when avcumdos_6wper <= calculated mv then 1

       when avcumdos_6wper > calculated mv then 2

       else 999 end as flag

from temp;

Can someone tell me what I am doing wrong?

2 REPLIES 2
Reeza
Super User

Are you on SAS 9.4? Before SAS 9.4 proc SQL cannot calculate the median.

ballardw
Super User

If median works it is only working on one record at a time with your syntax. My current SAS does not have the median function available in SQL but you may be looking for something like:

proc sql;

create table temp1 as

select patientid, visit, avcumdos_6wper, b.mv,

  case when avcumdos_6wper = .  then .

  when avcumdos_6wper <= b.mv then 1

       when avcumdos_6wper > b.mv then 2

       else 999 end as flag

from temp join (select median(avcumdos_6wper) as mv from temp) as b;

quit;


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
  • 2 replies
  • 719 views
  • 0 likes
  • 3 in conversation