- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In the error it gave me the second date variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you so much for your help. It worked.