BookmarkSubscribeRSS Feed
reem225
Calcite | Level 5

Hi,

 

I have a table with patient Id, treatment type, date of first prescription and date of last prescription. I want to create a new column (variable) which will return 1 if the first prescription date plus 30 days overlaps with the last prescription date, otherwise assign it a value of 0.  i tried using the retain function but no results. Can you please help me?

 

Capture.JPG

3 REPLIES 3
PGStats
Opal | Level 21

Assuming your dates are SAS dates:

 

overlap = intnx("DAY", date, 30) >= lastdate;

 

 

PG
reem225
Calcite | Level 5

Thank you so much!

 

they are sas dates and works!

reem225
Calcite | Level 5

I now noticed that once there is only 1 prescription and no last prescription the overlap is assigned as 1, is there a way to overcome that?

 

thank you

 

my code:Capture.PNG

data overlap ;
		set Rxfinal ;
		by id date ;
	    lagtrt= lag(treatment);
	    if first.id then lagtrt=treatment;
		if not first.id then lagtrt=0 ; 
		switch = intnx("DAY", date, 30) >= lastdate;
		run ;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1205 views
  • 0 likes
  • 2 in conversation