BookmarkSubscribeRSS Feed
sandhya88
Calcite | Level 5

Hi there, I am just trying some thing with some data that i have and it seems that i am missing out on following few of the conditions while trying to flag the baseline records based on my following conditions.

1. if there are several records for a single test in a visit with the same result  i need to flag the closest one to the target date.

2.if there are several records for a test on same visit with different results i need to flag the worst result as the baseline.

 

NOTE:R is the worst result for consideration

 

example data:

 

id test  visit  dy targetdy result

1  tst1   1      1        1            R

1  tst1   1     -29     1            R

1  tst1   1       1       1           S

 

I Am trying this code:

 

data xx;
set xx;
by id test visit result;
if result eq "S" then worstord=1;
else if result eq "R" then worstord=2;
run;

 

Proc sort data=xx; by id test visit worstord;run;

 

data blfl;
set xx;
by id test visit worstord;
if visit=1 and last.visit and worstord=2 then ABLFL="Y";
else if visit=1 and last.visit and worstord=1 then ABLFL="Y";
IF visit EQ 1 Then do;
if first.visit then numrec=1;
else numrec+1;
end;
run;

 

your help is much appreciated!!!!

 

Thanks alot

2 REPLIES 2
maguiremq
SAS Super FREQ

Hi @sandhya88, Thanks for providing some sample data that we can work with. Could you please show us what you want your dataset to look like?

 

Also, you mention date in reference to target date - is it supposed to be a date value?

sandhya88
Calcite | Level 5

Hi,

 

thanks for looking at my data

 

here is what i wanted it to look alike

 

id test  visit  dy targetdy result  baselineflg

1  tst1   1      1        1            R      Y

1  tst1   1     -29     1            R

1  tst1   1       1       1           S

 

sorry for the text above please consider the closest dy to targetdy.

 

 

Thanks

 

 

 

 

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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