BookmarkSubscribeRSS Feed
EM_G
Fluorite | Level 6

Hi All,

 

I know the topic of converting char var to sas dates has been covered a lot. Looking through the previous posts I have not found the answer to my question. 

I have dates in the format of 01Jan2014 and trying to compute a new column with the sas date as follows:

data new;

set have (rename=(date=old));

date = input (old,date9.);

drop old;

format date mmddyy10.;

run;

The log comes back as Note; Invalid argument to function input at line 64 in column 10

Why could I be getting this error?

Thanks

8 REPLIES 8
andreas_lds
Jade | Level 19

Difficult to help without seeing data and log. Maybe you don't have a proper date-string in some lines.

Kurt_Bremser
Super User

Look at the attributes of your existing date column. Is it in fact character?

Please post the log of the data step, including the complete code and the NOTE. It will contain a listing of the variable values at the time of the conversion problem.

Use this button to post the log:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

ballardw
Super User

You log also likely showed the value it attempted to read in that invalid data message.

Here is an example of a bad date string and what the log shows when you use the input function similar to your example:

26   data junk;
27      strdate='03JON2021';
28   run;

NOTE: The data set WORK.JUNK has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


29   data junk2;
30      set junk;
31      date = input(strdate,date9.);
32   run;

NOTE: Invalid argument to function INPUT at line 31 column 11.
strdate=03JON2021 date=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the
      operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 31:11

So you have cleverly hidden the actual problem value by not pasting the SECOND line of the Invalid argument note.

If you read your log carefully I strongly suspect you will find the problem dates are most likely to days of the month that are not valid like 31 November, or leap days for February in non-leap years.

EM_G
Fluorite | Level 6
ballardw thankyou, this makes a lot of things clearer to me now. I will go back and have a look.
Cheers
EM_G
Fluorite | Level 6
You are right that the log also says date=._ERROR_=1 _N_=1 all the way through to _N_=20 where limit set Errors are reached. They all happen to have the same original date old=01SEP2017. Could it be the uppercase SEP? Or; the original dataset was imported from excel, in excel the date was 1-SEP-2017, but when I imported it, SAS automatically formatted it to 01SEP2017, could the problem be here somewhere?
Tom
Super User Tom
Super User

@EM_G wrote:
You are right that the log also says date=._ERROR_=1 _N_=1 all the way through to _N_=20 where limit set Errors are reached. They all happen to have the same original date old=01SEP2017. Could it be the uppercase SEP? Or; the original dataset was imported from excel, in excel the date was 1-SEP-2017, but when I imported it, SAS automatically formatted it to 01SEP2017, could the problem be here somewhere?

It looks like the variable is already a numeric variable with the DATE9. format attached to it.  That would display date values in that style. So what are you trying to convert?  If you want the dates displayed differently then just use a different format with the variable.

 

Look at the definition of the variable in the SAS dataset. (for example run PROC CONTENTS on it) 

 

EM_G
Fluorite | Level 6
I would like it as a sas date. Can it be a sas date, but displayed as a format easier to recognise?
Tom
Super User Tom
Super User

Which of the 285 formats to you find more readable?

2321  data test;
2322    today=date();
2323    set sashelp.vformat ;
2324    where fmttype='F' and fmtinfo(fmtname,'cat')='date';
2325    if fmtname ^=: '$';
2326    value = putn(today,cats(fmtname,maxw,'.-L'));
2327    if compress(value,'*') ne ' ';
2328    keep fmtname value;
2329  run;

NOTE: There were 310 observations read from the data set SASHELP.VFORMAT.
      WHERE (fmttype='F') and (FMTINFO(fmtname, 'cat')='date');
NOTE: The data set WORK.TEST has 285 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.54 seconds
      cpu time            0.39 seconds

Personally I like to use YYMMDD10.  Then the value will sort lexigraphically in chronological order.  Plus unlike MMDDYY or DDMMYY you don't confuse half of your audience when the day number is 12 or less.   Does 10/12 mean October 12th or 10th December?  If you like the style your Excel sheet was using then try DATE11. to get hyphens.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 796 views
  • 0 likes
  • 5 in conversation