Hi Everyone
I'm trying to format a numeric date field from '2020-11-30' to Date9. 30NOV2020.
The below query is not working :
data want
set need
New_Date = input(Date, DDMMYYD10.);
format New_Date date9.;
run;
you do not need to convert as your var is already numeric. Just format
data want
set need
New_Date = input(Date, DDMMYYD10.);
format date date9.;
run;
Can you do a PROC CONTENTS and check the data type of the variable plz .
The Proc CONTENTS report will contain information about the metadata or for easy understanding so called properties. Should your Date be character, you would of course need to convert to a numeric SAS date and assign to a new variable that is of type numeric.
@Ela_84 If it all your date is of type char, it may appear your dates are in the from YYMMDD, and therefore the appropriate INFORMAT needed to convert to numeric would also be YYMMDD10.
So basically,
data test;
char_Date='2020-11-30';
num_sas_date=input(char_date,yymmdd10.);/*convert to numeric and save in a new var*/
format num_sas_date date9.;
run;
I was searching for 45 mins for the solution to this exact problem and this worked for me. Thank you so much!!!
You need to use a valid INFORMAT with the INPUT() function. There is no informat named DDMMYYD.
Also if the strings follow the pattern YYYY-MM-DD then you want to use the YYMMDD10. informat.
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: