BookmarkSubscribeRSS Feed
bhca60
Quartz | Level 8
        GOPTIONS ACCESSIBLE;
23         DATA NUMERATOR2;
24         SET NUMERATOR;
25         datedif=intck('day',dischargedate$10., eventdate$10.);
                                            ____
                                            388
                                            200
                                            76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

26         IF condition = "AAA" AND DATEDIF <= '14' THEN NUM = '1';
27         ELSE IF CONDITION = "HHH" AND DATEDIF <= '7' THEN NUM='1';
28         ELSE IF CONDITION = "CCC" AND DATEDIF <= '14' THEN NUM='1';
29         ELSE IF CONDITION = "DDD" AND DATEDIF <= '14' THEN NUM='1';
30         ELSE IF CONDITION = "EEE" AND DATEDIF <= '30' THEN NUM='1';
31         ELSE IF CONDITION = "PPP" AND DATEDIF <= '30' THEN NUM='1';
32         if datedif = . then DELETE;
33         run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      32:4   
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.NUMERATOR2 may be incomplete.  When this step was stopped there were 0 observations and 34 variables.
WARNING: Data set WORK.NUMERATOR2 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.08 seconds
      cpu time            0.01 seconds
      

How do I fix this? I'm trying to get a difference between two dates and also format those dates.

5 REPLIES 5
Kurt_Bremser
Super User

Formats are assigned with a FORMAT or ATTRIB statement, to use a variable in calculations you always use the variable name only.

 

And you cannot use a character format for date values, which are numeric.

bhca60
Quartz | Level 8
they are characters in my data with length 10
Reeza
Super User
datedif=intck('day',dischargedate, eventdate);

The 2nd and 3rd parameters are dates, so should just have the variable names.

 

The $10 are typically format references and are not valid in the function. 

 

If the dates are character and need to be converted to SAS dates that would be done differently. 

 

Tom
Super User Tom
Super User

To convert character strings into DATE values use an informat that matches the character pattern.

So if the 10 characters are in the pattern YYYY-MM-DD then use the yymmdd10. informat. Since dates are stored as number of days to find the difference in day just subtract.

datedif=input(dischargedate,yymmdd10.) - input(eventdate,yymmdd10.);

If the pattern is different then use the right informat for that pattern.

Kurt_Bremser
Super User

@bhca60 wrote:
they are characters in my data with length 10

WHY?

Such values need to be stored correctly as SAS date values when the data arrives in the SAS environment.

From which source do you get the data, and how do you import it?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 1223 views
  • 0 likes
  • 4 in conversation