BookmarkSubscribeRSS Feed
shami
Obsidian | Level 7

Hi everyone,

I would like to convert a numeric YYMMDD10. to a numeric Date9.
I have the following code but I'm not getting a result.

DATA WANT;
	SET HAVE;
                 
DATE = INPUT(tdy_date,YYMMDD10.);                              
FROMAT DATE DATE9.;                  
RUN;
1 REPLY 1
ballardw
Super User

INPUT function requires text. If you use a numeric value then SAS will do an automatic conversion from number to text using a best format that will have leading spaces and not match the YYMMDD10 expected values.

 

So control the conversion with a PUT function call

DATA WANT;
	tdy_date=20120712;
                 
   DATE = INPUT(put(tdy_date,8.),YYMMDD10.);                              
   ForMAT DATE DATE9.;                  
RUN;

If your data is clean you could re-use the variable name tdy_date and not create a new variable.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 297 views
  • 2 likes
  • 2 in conversation