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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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