BookmarkSubscribeRSS Feed
unnati
Obsidian | Level 7

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

4 REPLIES 4
Reeza
Super User

But this code give me error message and  no output

 

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

Tom
Super User Tom
Super User

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.

novinosrin
Tourmaline | Level 20

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

ballardw
Super User

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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 6428 views
  • 2 likes
  • 5 in conversation