Hi,
I was hoping someone here could help me figure out the solution to convert number to date.
I have a variable called M0906_DC_TR_DTH_DT with length of 4, format as YYMMDDN8. in the original date set. It was shown as 20130513 for example.
I have a trouble converting it into date.
I tried to use the following code but it didn't work.
DSCHRG_DT=input(put(M0906_DC_TR_DTH_DT, 8.), Yymmdd10.);
format DSCHRG_DT YYMMDDN8.;
I also tried to change the length of M0906_DC_TR_DTH_DT to 8 instead of 4. But it didn't work neither.
The note showed 'Invalid argument to function INPUT ......'
Any help with this regard will be greatly appreciated!
@Crystal_F wrote:
Hi,
I was hoping someone here could help me figure out the solution to convert number to date.
I have a variable called M0906_DC_TR_DTH_DT with length of 4, format as YYMMDDN8. in the original date set. It was shown as 20130513 for example.
I have a trouble converting it into date.
I tried to use the following code but it didn't work.
DSCHRG_DT=input(put(M0906_DC_TR_DTH_DT, 8.), Yymmdd10.); format DSCHRG_DT YYMMDDN8.;
I also tried to change the length of
M0906_DC_TR_DTH_DT to 8 instead of 4. But it didn't work neither.
The note showed 'Invalid argument to function INPUT ......'
Any help with this regard will be greatly appreciated!
If your variable shows that it has an existing format of YYMMDDN8. it is already a SAS date value.
What do you mean by "show as a date"? Likely all you need to do is change the display format.
You cannot change the length of a variable once created, and likely not needed.
You should show desired result of what you attempt along with code.
Here is an example of creating a variable of length 4 (number of bytes used to store a numeric, not related to display in any way) as a date value with a default format as you show and using a different format to display the value.
data junk; length x 4.; x = today(); format x yymmddn8.; run; proc print data=junk; title "Default format"; run; proc print data=junk; title "Different format applied"; format x worddate.; run;title;
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
If the length of the variable is 4, i suspect the date is truncated to only 4 characters. It should have length of 8.
DSCHRG_DT=input('20130513', yymmdd10.);
@Jagadishkatam wrote:
If the length of the variable is 4, i suspect the date is truncated to only 4 characters. It should have length of 8.
DSCHRG_DT=input('20130513', yymmdd10.);
FWIW, the largest value for length 4 is 2097152. Which "restricts" dates to a maximum of 23Oct7701.
@Crystal_F wrote:
Hi,
I was hoping someone here could help me figure out the solution to convert number to date.
I have a variable called M0906_DC_TR_DTH_DT with length of 4, format as YYMMDDN8. in the original date set. It was shown as 20130513 for example.
I have a trouble converting it into date.
I tried to use the following code but it didn't work.
DSCHRG_DT=input(put(M0906_DC_TR_DTH_DT, 8.), Yymmdd10.); format DSCHRG_DT YYMMDDN8.;
I also tried to change the length of
M0906_DC_TR_DTH_DT to 8 instead of 4. But it didn't work neither.
The note showed 'Invalid argument to function INPUT ......'
Any help with this regard will be greatly appreciated!
If your variable shows that it has an existing format of YYMMDDN8. it is already a SAS date value.
What do you mean by "show as a date"? Likely all you need to do is change the display format.
You cannot change the length of a variable once created, and likely not needed.
You should show desired result of what you attempt along with code.
Here is an example of creating a variable of length 4 (number of bytes used to store a numeric, not related to display in any way) as a date value with a default format as you show and using a different format to display the value.
data junk; length x 4.; x = today(); format x yymmddn8.; run; proc print data=junk; title "Default format"; run; proc print data=junk; title "Different format applied"; format x worddate.; run;title;
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
Your variable is a date. All you need to do is change the display format to your preferences.
A length of 4 gives sufficient numeric precision for dates.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.