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

I have a dataset where I have to convert dates (MM/DD/YYYY) from a character variable to a date variable.

After many different attempts, my code is still experiencing errors. Ultimately I want to convert the dates from character to numeric format and restrict my dataset to those observations only with date after 7/1/2014 following this step

 

the error message is

NOTE: Invalid argument to function INPUT"

 

 

code:

data data;

set data1;

newvar= INPUT(oldvar, date9.);

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

So if your dates are in MM/DD/YYYY format, why are you using date9. informat. Shouldn't you be using mmddyy10. infomat in your input function?

Like- 

data data;

set data1;

newvar= INPUT(oldvar, mmddyy10.);

if newvar>'01JUL2014'd;

run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

So if your dates are in MM/DD/YYYY format, why are you using date9. informat. Shouldn't you be using mmddyy10. infomat in your input function?

Like- 

data data;

set data1;

newvar= INPUT(oldvar, mmddyy10.);

if newvar>'01JUL2014'd;

run;

ballardw
Super User

It is good practice to assign some sort of date format to the result of a date value creation so us humans can see what date SAS resovled the value to.

Sometimes people think there text variable is in a layout such as mm/dd/yyyy but SAS reports errors becaus the values are actually dd/mm/yyyy. Or they are mixed. 05/04/2017: is this actualy May 4 or Apr 5. The ones that do not get an error may give you some hints when you look at them.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 1745 views
  • 2 likes
  • 3 in conversation