BookmarkSubscribeRSS Feed
Ela_84
Fluorite | Level 6

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;

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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;

Ela_84
Fluorite | Level 6
I get the below error

27 format Date Date9.;
______
484
NOTE 484-185: Format $DATE was not found or could not be loaded.
novinosrin
Tourmaline | Level 20

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;

 

zaval025
Calcite | Level 5

I was searching for 45 mins for the solution to this exact problem and this worked for me. Thank you so much!!!

Tom
Super User Tom
Super User

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.

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