Hello
I want to convert sas numeric/char into sas date.
Error-
29
30 data ttt2;
31 set ttt1;
32 SAS_date=input(put(x,best.),yymmddn8.);
_________
485
NOTE 485-185: Informat YYMMDDN was not found or could not be loaded.
data ttt1;
x=20200418;
run;
data ttt2;
set ttt1;
SAS_date=input(put(x,best.),yymmddn8.);
Run;
Try this
data ttt1;
x = 20200418;
run;
data ttt2;
set ttt1;
SAS_date = input(put(x,8.), yymmdd8.);
format SAS_date date9.;
Run;
Try this
data ttt1;
x = 20200418;
run;
data ttt2;
set ttt1;
SAS_date = input(put(x,8.), yymmdd8.);
format SAS_date date9.;
Run;
Informats do not have the special "x" characters, they don't care about the delimiters or absence of them (exception: YYMMN). Formats, OTOH, need them.
@Ronein wrote:
Hello
I want to convert sas numeric/char into sas date.
Error-
29
30 data ttt2;
31 set ttt1;
32 SAS_date=input(put(x,best.),yymmddn8.);
_________
485
NOTE 485-185: Informat YYMMDDN was not found or could not be loaded.
data ttt1; x=20200418; run; data ttt2; set ttt1; SAS_date=input(put(x,best.),yymmddn8.); Run;
Suggest that any time you are attempting to use the put numeric value and input for date such as with:
SAS_date=input(put(x,best.),yymmddn8.);
That you 1) use a format other than BEST (large/small values may create exponential notation that none of the Date/time/datetime informats will like and 2) that you use the -L instruction to left justify the resulting text. Consider this example.
data example; x=20200418; y=quote(put(x,best.)); run;
The quote function places quotes around the value of the Put. Note that the result has 4 leading spaces because the default Best uses a width of 12 and your value had 8 characters as an integer. That is because PUT with numeric values by default right justifies the result. So whatever INFORMAT attempts to use that result will first encounter 4 spaces and likely fail to read the values you want.
Example:
data example; x=20200418; z=input(put(x,best.),f8.); run;
Z has the value of 2020 because the first 8 characters were 4 spaces and then the first 4 digits of 20200418. So the Date informat would only see 2020 and almost certainly fail.
The -L instruction to the Put function left justifies the result.
data example; x=20200418; z=input(put(x,best. -L),f8.); run;
Personally instead of best I would use an 8. format with put if I expect 8 characters in the result which would be less likely to have issues for these reasons. But I still use a -L with the put just in case.
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 lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.