BookmarkSubscribeRSS Feed
enigmaticepi
Calcite | Level 5

Hi am have a clinical dataset of multiple observations per patient, with the number of visits varying widely. I want to find whether the baseline levels for each patient are abnormal (above a certain value), however, there are a few patients where the first value is missing for one of my variables on the first visit date, so I am struggling with this. At first I used first.id, but realized I wasn't putting everyone in the right boxes because of the missings Any advice how to approach this? 

                                                            id         datechem        CREAT  AST       ALKP    TBILI   N_VISITS

415MAR20180.819580.56
416MAR20180.819580.56
420MAR20180.718..6
423MAR20180.623..6
403APR20180.633..6
406APR20180.729..6
513JUL2018.36135.7
518JUL20181.1241230.37
528JUL20180.923920.37
2.0107AUG1989....7
                         
           
         
7 REPLIES 7
Astounding
PROC Star

Are you asking for the earliest non-missing value for each test? 

 

Here's an easy way (although it may leave a few stray variables hanging around):

 

proc sort data=have;

by id descending datechem;

run;

 

data want;

update have (obs=0) have;

by id;

run;

PGStats
Opal | Level 21

@Astounding, I think adding if last.id; would eliminate non meaningful data from the result set.

PG
Astounding
PROC Star

@PGStats,

 

Actually, it's automatic.  UPDATE outputs just the final observation for each BY group.

 

I might add dropping a variable or two from the result, such as the date variable.

PGStats
Opal | Level 21

Had forgotten about that. Thanks @Astounding.

PG
enigmaticepi
Calcite | Level 5

Hi, thanks for your reply!

So I ran this and it looks like it just printed the last chemdate for each patient.

 

Not really sure if I just did something wrong. 

 

I was wanting to print the second observation for ID because it is the first non-missing observation or just get this date. Is there a way to do this? 

 

I was thinking of using something like this? I already have code for getting the date of the first abnormal value, I just don't have a way to tell if this occurred on the first test or not, so thought if I got a first test date (creatdate below) I could just compare them. 

 



retain inint creatdate enddate;
keep ptindex creatdate enddate interval ;

if first.ptindex then inint=0;

if (inint=0) and (creat GT .) then do;
creatdate=datechem;
inint=1;
end;

 

if last.ptindex=1 and inint=1 then do;
interval=(enddate-begdate);
output;
end;

format begdate date9. enddate date9.

 

Thanks again for your help!

                                                           ID         datechem   CREAT      AST       ALKP  TBILI    N_VISITS

315MAR2000.19580.56
316MAR20001.619580.56
320MAR20000.718..6
323MAR20000.623..6
303APR20000.633..6
306APR20000.729..6
413JUL20000.8361350.47
418JUL20000.8241230.37
428JUL20000.923920.37
407AUG2000....7
414AUG2000.65..7
421AUG2000.68..7
428AUG2000.66..

7

mkeintz
PROC Star

The where filter is your friend;

 

 

data want;
  set have (where=(nmiss(ast,alkp)=0));
  by id;
  if first.id;
run;

 

The nice thing about WHERE filters is that they are exported to the data engine.  So such observations are never seen in the data step.  As a result the "first.id" test will be the first instance of nonmissing AST and ALKP for each id.   BTW, you could just as well use a where STATEMENT as opposed to a where dataset name parameter.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

It should have printed the first DATECHEM for each, not the last.  Make sure you sorted properly.  Or better, yet, just drop DATECHEM.  If you spot check the numbers, they should be 100% correct.

 

This approach isn't intended to select a single observation.  It will select the first nonmissing CREAT, the first nonmissing AST, the first nonmissing ALKP, etc. for each ID.  They could easily be selected from different incoming observations.

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
  • 7 replies
  • 536 views
  • 2 likes
  • 4 in conversation