BookmarkSubscribeRSS Feed
YuWeiLee
Calcite | Level 5

Hi everyone,

 

I want to convert character mmddyy to numeric, here is my data :

 

Date

03/31/1980 (format$10)

06/30/1980

12/31/1980

 

I try my best to convert it to YYMMDDN8. , but it still doesn't work. I hope that somebody could help me to solve this problem.

 

Many thanks.

 

 

3 REPLIES 3
Astounding
PROC Star
You must create a new variable:

data want;
set have;
newvar = input(date, mmddyy10.) ;
format newvar yymmddn8.;
run;

If you want to keep the original variable name, you could add:

drop date;
RENAME newvar = date;
hashman
Ammonite | Level 13

As @Kurt_Bremser and @Astounding have pointed out, MMDDYY10. is the correct informat in this situation.

However, if in doubt, you can use the ANYDTDTEw. informat with a sufficiently long w, which is quite darn good at recognizing various character date patterns with a garden variety of delimiters used. For example, run this step for a demo:

data _null_ ;                                            
  retain dlmstr " ~!#$%^&*()-_=+[]{}\|;:.<>?" ;          
  length cdate $ 10 ;                                    
  do i = 1 to length (dlmstr) ;                          
    cdate = catx (char (dlmstr, i), "09", "11", "2001") ;
    ndate = input (cdate, anydtdte10.) ;                 
    put cdate ndate yymmdd10. ;                          
  end ;                                                  
run ;                                                 

Kind regards

Paul D.    

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!

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
  • 3 replies
  • 1718 views
  • 0 likes
  • 4 in conversation