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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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