Hi All,
I have a dataset in csv format and I can import it to SAS data, but there is particular variable for date and time in the format of 200428202835 (which is YYMMDDHHMMSS). I wanted to read this variable as in proper format like date9. and time5. Is there any option to get above formatted date and time in this format.
Best Regards,
Sairam
One way:
data example; x = '200428202835'; date = input(x,yymmdd6.); time = input(substr(x,7), hhmmss.); format date date9. time time8.; run;
You will likely need to read the value as character and then parse because this is a pretty non-typical format.
And talk to whoever is using 2 digit years. Did they not learn anything from Y2K?
One way:
data example; x = '200428202835'; date = input(x,yymmdd6.); time = input(substr(x,7), hhmmss.); format date date9. time time8.; run;
You will likely need to read the value as character and then parse because this is a pretty non-typical format.
And talk to whoever is using 2 digit years. Did they not learn anything from Y2K?
Thank you very much for the resolution. I would reach to my data manager to check the Y2K.
@Sairampulipati wrote:
Thank you very much for the resolution. I would reach to my data manager to check the Y2K.
If you can get the century digits included then your strings will match the B8601DJ informat.
Hi @Sairampulipati,
Assuming that you are using the most recommended technique for reading CSV files, a DATA step with INPUT statement(s), you can mix input styles and switch to formatted input for just the date part of this particular field.
Example:
data want;
infile cards dsd;
input seqno name $ date yymmdd6. time :hhmmss. amt :dollar.;
format date date9. time time8.;
cards;
1,John Doe,200428202835,$1234.56
;
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!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.