DATA Step, Macro, Functions and more

character date value to character IS8601DA. format

Reply
Occasional Contributor
Posts: 10

character date value to character IS8601DA. format

How do I convert character date value (yyyy-mm-dd) to character IS8601DA format?

 

For Example

STARTDATE        NEWDATE

29 OCT 2009       (I would like IS8601DA format date in this variable)

 

I have try code as follow:

 

Data ab

SET cd;

NEWDATE=INPUT(STARTDATE,DATE11.);

FORMAT NEWDATE IS8601DA.;

RUN;

 

 

But this code give me error message and  no output

Super User
Posts: 23,370

Re: character date value to character IS8601DA. format

But this code give me error message and  no output

 

What's the error message? Please post your full log, including the error message.

Super User
Super User
Posts: 7,948

Re: character date value to character IS8601DA. format

Post the log with the error message.  Make sure to use the {i} icon on the editor menu to open a pop-up window to paste in the lines from the SAS log. This will prevent the forum editor from reflowing the lines and removing the spacing that makes them readable.

PROC Star
Posts: 1,605

Re: character date value to character IS8601DA. format

where's the error and what error, log please. Your code seems to work fine when i ran :

data w;
STARTDATE ='29 OCT 2009';

NEWDATE=INPUT(STARTDATE,DATE11.);

FORMAT NEWDATE IS8601DA.;

RUN;

361 data w;
362 STARTDATE ='29 OCT 2009';
363
364 NEWDATE=INPUT(STARTDATE,DATE11.);
365
366 FORMAT NEWDATE IS8601DA.;
367
368 RUN;

NOTE: The data set WORK.W has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

Super User
Posts: 13,365

Re: character date value to character IS8601DA. format

Do you by any chance have any leading blank spaces in that character variable?

See this for a brief example of what happens in that case:

data example;
   x='29 OCT 2009';
   datex = input(x,date11.);
   /* one or more leading spaces*/
   y=' 29 OCT 2009';
   datey = input(y,date11.);
   format datex datey is8601da.;
run;

If that is the case for some values the use:  input(left(startdate), date11.); to remove the leading spaces.

 

Ask a Question
Discussion stats
  • 4 replies
  • 102 views
  • 2 likes
  • 5 in conversation