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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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