BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tnachis
Fluorite | Level 6

I am trying to create a rolling 1 Year date range. 

I have realized that when i use this date format datetime20. the date shows ' 01JAN1960:06:09:19'dt.

 

data null;
format pre_mth End_year instance_date instance_date1 instance_date2 date9.;
pre_mth=%sysfunc(intnx(month,&valdate.,-1,B));
End_year=intnx('day',pre_mth,-365);
call symput('instance_date', "'" || put(End_year, date9.)|| "'dt");
call symput('instance_date1', "'" || put(End_year, datetime20.)|| "'dt");
call symput('instance_date2', "'" || put(pre_mth, datetime20.)|| "'dt");
Run;
%put &instance_date1;
%put &instance_date2;

 

The goal is to create a date range for instance between ' 01SEP2021:06:09:19'dt and  ' 01SEP2020:06:09:19'dt

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Maxim 28: Macro Variables Need No Formats.

If you want to use those values for comparisons/cutoffs in code, the raw value is sufficient and much easier to handle.

end_year is obviously a date, so using a datetime format for it makes no sense and results in times on day zero (1960-01-01).

 

You should calculate end_year by using YEAR as interval:

end_year=intnx('year',pre_mth,-1,"s");

which automatically takes care of leap years.

 

So, how do you intend to use these values later in code?

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

I'm not entirely sure what a "1 Year date range" and what you're trying to do? 🙂

Kurt_Bremser
Super User

Maxim 28: Macro Variables Need No Formats.

If you want to use those values for comparisons/cutoffs in code, the raw value is sufficient and much easier to handle.

end_year is obviously a date, so using a datetime format for it makes no sense and results in times on day zero (1960-01-01).

 

You should calculate end_year by using YEAR as interval:

end_year=intnx('year',pre_mth,-1,"s");

which automatically takes care of leap years.

 

So, how do you intend to use these values later in code?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Update

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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