@marleeakerson wrote:
Hello,
I need some help converting a numeric variable into a SAS date variable.
I am trying to get the last day of the month into a new variable. The original variable is "Date_Collect" which is a date variable, then I used the intnx function to grab the last day of the month. The step I am struggling with is converting the lastday variable into a SAS date variable instead of a numeric variable.
When I run this code, lastday_date is entirely blank.
Any ideas?
data want;
set have;
lastday_num=intnx('month',Date_Collect,0,'E');
lastday_date=input(put(lastday_num,date8.),yymmdd8.);
format lastday_date date8.;
run;
Besides NOT needing
lastday_date=input(put(lastday_num,date8.),yymmdd8.);
because lastday_date is a date value, you are making a value that cannot be read with yymmdd8. When put a date with date8. format then you get a value with a leading space that looks like " 01SEP20". YYMMDD8 expects numerals that represent year month and day, like 20200901 (for 01SEP2020).
The leading space created by DATE8 means almost any informat would fail.
If you find someone using code that has any code that uses: input(put(variable,<some date format>), <some date informat>)
then do NOT copy that. The variable is Already a date value and changes in appearance just require a Format assignment or the variable is not a date and will yield unexpected results.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354 has a PDF with much information about dates.
... View more