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?
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!
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.