Hi Team,
In my dataset I have a date format as YYYYMMDD, but I am tryng to convert it to MMDDYYYY format.
Please suggest.
Here is the example;
Data a;
input Dat ;
cards;
20191026
run;
Requiered output:
Dat
10262019
Thanks,
Sanjay
@sanjay1 wrote:
I did the contents here is the result.
Variable Type Len Format Informat Label
Dat Num 8 9. 9. Dat
OMG.
Well, in that case, you need to do a double conversion:
dat = input(put(dat,z8.),yymmdd8.);
format dat mmddyy8.;
Create a new dataset in a step where you use this, so you do not destroy your incoming data if something fails.
Read into a SAS date with the proper informat, and use the proper display format:
Data a;
input Dat yymmdd8.;
format Dat mmddyyn8.;
cards;
20191026
;
Hi @sanjay1 ,
You need to specify an informat so that SAS correctly reads input data as dates and not numbers.
Once, it has been correctly interpret as a date, you can apply the format you want.
Hope this help!
Data a;
input Dat ;
informat Dat YYMMDD10.;
format Dat MMDDYY10.;
cards;
20191026
;
run;
Hi,
I am not creating it manually I am pulling it form from database.
Then you need to get a clear picture of your data. Run a proc contents on the dataset to see how the variable is defined. From that you can infer the real content.
No sane database admin stores a date as a 8-digit number.
I did the contents here is the result.
Variable Type Len Format Informat Label
Dat Num 8 9. 9. Dat
@sanjay1 wrote:
I did the contents here is the result.
Variable Type Len Format Informat Label
Dat Num 8 9. 9. Dat
OMG.
Well, in that case, you need to do a double conversion:
dat = input(put(dat,z8.),yymmdd8.);
format dat mmddyy8.;
Create a new dataset in a step where you use this, so you do not destroy your incoming data if something fails.
Thank you @Kurt_Bremser , Its working
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.