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
But this code give me error message and no output
What's the error message? Please post your full log, including the error message.
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.
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.