I have this date variable (numeric, format DATE9.) that appears as 01DEC2011. I need to change that to this format: 12/29/2011.
I seem to be missing something in my code (see below) because i'm getting missing values for the new date variable.
start_dt_n = INPUT(PUT(start_dt,10.),YYMMDD10.);
FORMAT start_dt_n MMDDYY10.;
Any hints on how to fix this?
Thanks
Try
start_dt_n = start_dt;
FORMAT start_dt_n MMDDYY10.;
or change the format of start_dt to mmddyy10.
If the variable is really numeric and a true SAS date, then all you need to do is change the format of the variable. There are many ways this format change can be done, the simplest might be to re-create the data set using the desired format.
Try
start_dt_n = start_dt;
FORMAT start_dt_n MMDDYY10.;
or change the format of start_dt to mmddyy10.
@ama220 wrote:
I have this date variable (numeric, format DATE9.) that appears as 01DEC2011. I need to change that to this format: 12/29/2011.
I seem to be missing something in my code (see below) because i'm getting missing values for the new date variable.
start_dt_n = INPUT(PUT(start_dt,10.),YYMMDD10.);
FORMAT start_dt_n MMDDYY10.;
Any hints on how to fix this?
Thanks
if start_dt is already a SAS date value then a value equivalent to 01DEC2011 is numerically 18962. SAS dates are stored as the number of days from 01JAN1960. So put(start_dt,10.) would be " 18962". Note the leading blanks. That would be cause of your missing values and your LOG would have had a bunch of lines like:
NOTE: Invalid argument to function INPUT at line 104 column 3. start_dt=18962 y=. _ERROR_=1 _N_=1
Formats are a very powerful and flexible tool in SAS. You change the analysis of groups of date values just by changing the format for the duration of a procedure. You do not have to make the change permanent.
An example of using different formats for different analysis with proc freq. Change HAVE to the name of your data set.
proc freq data=have; tables start_dt; format start_dt mmddyy10.; run; proc freq data=have; tables start_dt; format start_dt YYQ.; run; proc freq data=have; tables start_dt; format start_dt Year4.; run;
One counts values by calendar date, next values by calendar quarter and the last by calendar year. Note that the permanent format is not affected (though will be applied if you create output sets using the out option). This can be done with almost any procedure.
And custom formats can be applied to your specific groups of values as well.
Hi,
I'm using SAS on demand and I'm struggling to change a numeric to a SAS date.
My numeric variable is SurgStart which as format best12. and informat best32.
My code is:
data ab1;
set ab;
date_var=input(put(SurgStart, best12.),yyyymmdd.);
format date_var date9.;
run;
This doesn't work. What I want to happen is for SurgStart e.g.20140410 to become the date 2014-04-10 so I can then do time series analysis.
Please help!
Why is this
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: