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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.