DATA Step, Macro, Functions and more

Problem formatting date defined with format 'IS8601DN10' & informat 'DateTime20'

Reply
Frequent Contributor
Posts: 82

Problem formatting date defined with format 'IS8601DN10' & informat 'DateTime20'

I am reading dataset in a sas program (stored process) which was created from another system.  This file has some of the date column formats defined as  'IS8601DN10' and informat as 'DateTime20'.   In viewing the table, the date displays as 'YYYY-MM-DD'.   I am trying to format the date to the format of 'mm/dd/yyyy' and I have not been successful in doing so.     I've spend several hours on this and am quite frustrated.  Any help/suggestions would be greatly appreciated!

 

I have never seen any data come in that used this 'IS860' type format.

 

Thanks for any help that can be offered!!!

SAS Super FREQ
Posts: 683

Re: Problem formatting date defined with format 'IS8601DN10' & informat 'DateTime20'

Hi

 

When you are using the IS8601DN10 (documented as E8601DN format), you are actually have a datetime value. So to display it using the MMDDYY. format you need to extract just the date part of the datetime value.

 

The code below illustrates this.

data sample;
  xDate = datetime();
  xDate2 = datepart( xDate );
  format
    xDate IS8601DN10.
    xDate2 mmddyy10.
  ;
run;

proc print data=sample ; 
run;

Bruno

Super User
Posts: 5,083

Re: Problem formatting date defined with format 'IS8601DN10' & informat 'DateTime20'

I like Bruno's answer better than mine, since it forces you to understand what is in your data.  With that being said, you have enough to work with once you understand that expressing your variable in the IS8601DN10 format gives you YYYY-MM-DD.  Knowing just that much, you could code:

 

newvar = (put(oldvar, IS8601DN10.), yymmdd10.);

 

That gives you NEWVAR as a SAS date, without even knowing what is in OLDVAR.  Just add a format:

 

format newvar mmddyys10.;

Super User
Posts: 5,083

Re: Problem formatting date defined with format 'IS8601DN10' & informat 'DateTime20'

Meant to add INPUT:

newvar = input(put(oldvar, IS8601DN10.), yymmdd10.);
Ask a Question
Discussion stats
  • 3 replies
  • 240 views
  • 0 likes
  • 3 in conversation