Hello all,
I have two dates and I need to calculate difference between them, but both the date variables are character variables, so I used INPUT function to convert it to numeric but I am getting error message 'Invalid argument to function INPUT at line'. Below is my code, can anyone please help me with this issue?
@billi_billi wrote:
In the error it gave me the second date variable.
That looks NOTHING like the type of string that the DATE informat can read.
What INFORMAT should you use?
SAS should have shown you the actual values of BASELINE_DATE that caused the issue.
Let's make some example strings and see what happens.
data test;
input string $char20.;
date = input(string,date9.);
format string $quote. date date9.;
cards;
01JAN2024
1jan24
1-jan-2024
01JAN2024
;
Here is the LOG
1 data test; 2 input string $char20.; 3 date = input(string,date9.); 4 format string $quote. date date9.; 5 cards; NOTE: Invalid argument to function INPUT at line 3 column 10. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 8 1-jan-2024 string="1-jan-2024" date=. _ERROR_=1 _N_=3 NOTE: Invalid argument to function INPUT at line 3 column 10. 9 01JAN2024 string=" 01JAN2024" date=. _ERROR_=1 _N_=4 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). 2 at 3:10 NOTE: The data set WORK.TEST has 4 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 10 ;
Can you tell why it did not like lines 9 and 10?
Can you think of a way to fix the code so they work?
11 data test;
12 input string $char20.;
13 date = input(left(string),date11.);
14 format string $quote. date date9.;
15 cards;
NOTE: The data set WORK.TEST has 4 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
20 ;
In the error it gave me the second date variable.
@billi_billi wrote:
In the error it gave me the second date variable.
That looks NOTHING like the type of string that the DATE informat can read.
What INFORMAT should you use?
thank you so much for your help. It worked.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.