BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

I need to find out if DateofService that are within 30 days of the dischargedate.

I appreciate your help.

Regards,

blue & blue

Blue Blue
8 REPLIES 8
Tom
Super User Tom
Super User

If they both contain DATE values then just test is the absolute value of the difference is less than or equal to 30.

Make sure to protect against missing values and SAS will consider a missing value as less than any actual number.

if -1 < abs(DateofService-dischargedate) <= 30 then .....
GN0001
Barite | Level 11

Hello Tom,

Thanks for your response. 
why should I use abs?
if dateofservice is less than discharge date, then that is ok. We want to find out those records when they had a visit within 30 days after their discharge.

if we use abs, then we can’t find out within 30 days after thr discharge date.

can’t we use datedif?

 

how should I guard against missing values? If discaregedate or dateofservice ne.?

yes both values are dates. I think if the result is positive, then dos has occurred after discharge date. Then, I need to find out if it is between 0 to 30 days.

regards 

blue & blue

Blue Blue
SASKiwi
PROC Star

Just swap your variables then:

if 1 <= (dischargedate - DateofService) <= 30;

Not sure what happens if both happen on the same day. Do you want to count those? If so change the 1 to 0.

GN0001
Barite | Level 11
Hello,
Why don’t I say if difference is > 0 and <= 30?
And should I find the difference first and then bring if?
Respectfully,
Blueblue
Blue Blue
SASKiwi
PROC Star

"Why don’t I say if difference is > 0 and <= 30?"

You'll get the same results as in my logic.

 

"And should I find the difference first and then bring if?"

Up to you, which ever way is best for you. There is no right or wrong answer here.

 

Tom
Super User Tom
Super User

Because you asked for "within 30 days", which would imply plus or minus 30 days.

 

GN0001
Barite | Level 11

Hello Kurt,

What you have directed me are links after links. If I want to get that route, I would be lost and each day, I need to start working in a new company. Obviously, reading is essential part of gaining education, I always read and search and then I post my question here.

I clicked on the links then other links came up and then till seven layers deep that I forgot what I wanted.

Anyway, thank you for sending me the direction that I go back and read them after I deliver my projects. I have short deadlines.

 

Respectfully,

Blue & Blue

Blue Blue

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1438 views
  • 6 likes
  • 4 in conversation