BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sanjay1
Obsidian | Level 7

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

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@sanjay1 wrote:

Hi @Kurt_Bremser 

 

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.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

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
;
ed_sas_member
Meteorite | Level 14

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;
sanjay1
Obsidian | Level 7

Hi,

 

I am not creating it manually I am pulling it form  from database.

 

Kurt_Bremser
Super User

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.

sanjay1
Obsidian | Level 7

Hi @Kurt_Bremser 

 

I did the contents here is the result.

 

Variable  Type   Len    Format    Informat      Label 

Dat         Num    8        9.              9.              Dat

 

 
Kurt_Bremser
Super User

@sanjay1 wrote:

Hi @Kurt_Bremser 

 

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.

sanjay1
Obsidian | Level 7

Thank you @Kurt_Bremser , Its working

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 7718 views
  • 3 likes
  • 3 in conversation