BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

Hello

I wan to change date format from Best12. / informat 12. to yymmn6.

I do this but it does'nt work 

data todate;
set FF_5factors;
sasdate = input(put(date,best12.),yymmn6.);
format date;
format sasdate yymmn6.;
run;

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Are any of your date values between Jan 1, 2000 (000101 in your DATE values) and Dec 31, 2009 (091231)?  If so, then the leading zeroes would be removed by BEST. format, producing erroneous or missing sasdate values.

 

Consider using

 

    sasdate=input(put(date,z6.),yymmdd6.);

And of course, make sure you have an appropriate value for the YEARCUTOFF global option  (see YEARCUTOFF= System Option ).

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

3 REPLIES 3
ballardw
Super User

It would be best to provide some examples of values and what date you expect as a result.

 

(put(date,best12.)

if there are only 6 digits in the value of date will result in 6 leading blanks. Which would be invalid data for the YYMMn6. informat.

Try the -L option to left justify the result so there are no leading blanks

(put(date,best12. -L)

or if you are sure there are only 6 digits

(put(date, 6.)
mkeintz
PROC Star

Are any of your date values between Jan 1, 2000 (000101 in your DATE values) and Dec 31, 2009 (091231)?  If so, then the leading zeroes would be removed by BEST. format, producing erroneous or missing sasdate values.

 

Consider using

 

    sasdate=input(put(date,z6.),yymmdd6.);

And of course, make sure you have an appropriate value for the YEARCUTOFF global option  (see YEARCUTOFF= System Option ).

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

Note that the FORMAT attached to a variable is just instructions for how to print the value.  So just knowing that you want to print the value using a maximum of 12 characters with flexibility about where to place the decimal point based on the individual values, which is what the BEST12. format specification means, does not help us understand what type of values you actually have.

 

To know how to convert the values into date values (if they are not already date values) we would need to see some of the actual values. 

 

If you have numbers like 202 thousand 4 hundred and 6 that you want to interpret that integer as meaning some time in June of 2024 then first convert it into a 6 digit string (not the 12 character string your code is making) before reading it with the YYMMN6. informat.

sasdate = input(put(date,z6.),yymmn6.);

If instead you have an actual date values (for example the date 01JUN2024 would be the number 23,528) then all you need to do is change the format attached the value to have it print as the six digit strings like 202406.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 487 views
  • 3 likes
  • 4 in conversation