BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data ttt1;
   x = 20200418;
run;

data ttt2;
   set ttt1;
   SAS_date = input(put(x,8.), yymmdd8.);
   format SAS_date date9.;
Run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Try this

 

data ttt1;
   x = 20200418;
run;

data ttt2;
   set ttt1;
   SAS_date = input(put(x,8.), yymmdd8.);
   format SAS_date date9.;
Run;
ballardw
Super User

@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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 461 views
  • 1 like
  • 4 in conversation