I'm working on a job and need to convert a character date (yyyy-mm-dd) from a source table over to a "mm/dd/yyyy" format in the target table. I'm not saavy enough yet to make this edit in the code, so I'm trying to do everything in the Expression Builder for now until I'm a little more well versed.
Well if the character string has the year first then trying to read it using MMDDYY10. informat will of course generate an error. There is no month number 2009! Use YYMMDD10. informat (note do not need to specify the N,S,D letter in the INFORMAT that you would need in the FORMAT).
I think that two date functions will do it for you:
OutDate = put(input(InDate, yymmdd10.), mmddyys10.);
Works perfect Tom, thank you kindly
Actually, that's giving me the wrong digits for the year. For example, a "June 29 2010" date is coming out like: 06/29/20
That's REALLY weird! Unfortunately, I don't have DI Studio available, I just mocked this up in Base SAS. If I run this program:
data Dates;
InDate = '2010-06-29';
OutDate = put(input(InDate, yymmdd10.), mmddyys10.);
output;
run;
the output is:
InDate | OutDate |
2010-06-29 | 06/29/2010 |
You're actually correct, except it keeps it as a Character type when it is preferred to keep a date in Numeric. So what I'm left with is: OutDate = INPUT(InDate,mmddyys10.) but that's generating an error for me and so I'm back to square one.
Well if the character string has the year first then trying to read it using MMDDYY10. informat will of course generate an error. There is no month number 2009! Use YYMMDD10. informat (note do not need to specify the N,S,D letter in the INFORMAT that you would need in the FORMAT).
Ok, it's for sure solved this time. Keeping it in a Numeric type and using the expression:
OutDate = INPUT(InDate , yymmdd10.)
AND
A Format of "mmddyy10."
Whew! Thank you both!
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.