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
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?
I'm not entirely sure what a "1 Year date range" and what you're trying to do? 🙂
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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.