BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AshJuri
Calcite | Level 5

Hi everyone, I am trying to convert a date variable that is stored as a character variable into a numeric variable. However, the date variable is in the format "02 AUG 2017". I want the result outputted as a new date variable that is numeric.

data want;
  set have;
  date=input(character_date,date10.);
  format date date10.;
run;

Nothing that I have tried has worked. I would appreciate any assistance. Thank you in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Count the number of characters in your string, including the blanks, and you will see that you need to read 11 characters.

Therefore this works:

data want;
character_date = '02 aug 2017';
date=input(character_date,date11.);
format date date9.;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Count the number of characters in your string, including the blanks, and you will see that you need to read 11 characters.

Therefore this works:

data want;
character_date = '02 aug 2017';
date=input(character_date,date11.);
format date date9.;
run;
ballardw
Super User

And if your data is a bit sloppy about consistent lengths you may want a different informat with more flexibility.

data want;
	character_date = '02 aug 2017';
	date=input(character_date,anydtdte.);
	format date date9.;
run;

The Anydtdte format by default allows more characters and will read some fairly messy dates but caution is needed if you have two-digit years at the start of your date.

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 882 views
  • 1 like
  • 3 in conversation