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

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?

 

proc sql;
 create table baseline as
     select 1 as order,usubjid, VISIT, VESTDTC, VESTDY
  from ve
  where VISIT = 'Baseline';
  quit;
 
 
proc sql;
 create table visits as
 
      select 1 as order, usubjid, VISIT, VESTDTC,VESTDY
  from ve
  where VISIT = 'Visit 2';
 quit;
 
 
   proc sort data=baseline (rename=(VESTDTC=baseline_date));
  by USUBJID;
run;
 
   proc sort data=visits;
  by USUBJID;
   RUN;
 
 data combined;
  merge baseline visits;
   by usubjid;
   run;
 
   data change;
    set combined;
numBase_date=INPUT(baseline_date,date9.);
  format numBase_date date9.;
  run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@billi_billi wrote:

In the error it gave me the second date variable.

billi_billi_0-1708734408315.png

 


That looks NOTHING like the type of string that the DATE informat can read.

What INFORMAT should you use?

Spoiler
That is something you would need to use YYMMDD10. informat to read.

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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?

Spoiler
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   ;

 

billi_billi
Calcite | Level 5

In the error it gave me the second date variable.

billi_billi_0-1708734408315.png

 

Tom
Super User Tom
Super User

@billi_billi wrote:

In the error it gave me the second date variable.

billi_billi_0-1708734408315.png

 


That looks NOTHING like the type of string that the DATE informat can read.

What INFORMAT should you use?

Spoiler
That is something you would need to use YYMMDD10. informat to read.
billi_billi
Calcite | Level 5

thank you so much for your help. It worked.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1171 views
  • 0 likes
  • 2 in conversation