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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1401 views
  • 1 like
  • 3 in conversation