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

I was wondering if someone can help me with the following query. It does not work:

 

%LET START_DATE = '07-SEP-2022';
%LET END_DATE = '07-SEP-2022';

DATA _NULL_;
DAYS_DIFF = INTCK('DAY', &START_DATE, &END_DATE);
RUN;

 

LOG:

 

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
-7805904:*** -7805903:***
NOTE: Invalid numeric data, '07-SEP-2022' , at line -7805904 column ***.
NOTE: Invalid numeric data, '07-SEP-2022' , at line -7805903 column ***.
DAYS_DIFF=. _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at -7805905:***
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
DATA _NULL_;

DAYS_DIFF = INTCK('DAY', input(&START_DATE, date11.), input(&END_DATE, date11.));
PUT DAYS_DIFF;
RUN;

View solution in original post

7 REPLIES 7
Reeza
Super User

Date literals in SAS are in the DATE9 format. 

 

%LET START_DATE = '07SEP2022'd;
%LET END_DATE = '07SEP2022'd;

DATA _NULL_;
DAYS_DIFF = INTCK('DAY', &START_DATE, &END_DATE);
DAYS_DIFF2 = &end_date - start_date;
put Days_Diff Days_DIff2;
RUN;
Emoji
Fluorite | Level 6

Thanks but I need to keep my macro variables untouched because I use them in the rest of my code and they need to be expressed as follows:

 

%LET START_DATE = '07-SEP-2022';
%LET END_DATE = '07-SEP-2022';

Reeza
Super User
DATA _NULL_;

DAYS_DIFF = INTCK('DAY', input(&START_DATE, date11.), input(&END_DATE, date11.));
PUT DAYS_DIFF;
RUN;
Emoji
Fluorite | Level 6

Thank you for your help. it worked/ 

Tom
Super User Tom
Super User

@Emoji wrote:

Thanks but I need to keep my macro variables untouched because I use them in the rest of my code and they need to be expressed as follows:

 

%LET START_DATE = '07-SEP-2022';
%LET END_DATE = '07-SEP-2022';


So to use INTCK() you need to convert those quoted strings into actual date values.

 

Since those values are in a style that the DATE informat can understand and already have quotes around them all you need to do is add the letter D after each to make them into something SAS will see as a date value.

data want;
  months = intck('month',&start_date.d,&end_date.d);
run;

If you had some other style then you would need to use the INPUT() function to convert those strings into dates, as long as the style of the strings is something understood by a SAS informat.

Example:

%LET START_DATE = '2022-09-07';
data _null_;
  date = input(&start_date,yymmdd10.);
run;
Emoji
Fluorite | Level 6

Thanks a lot. it worked!

ballardw
Super User

Not valid date literals. You need to have the D to make SAS use the value as date. Otherwise it is a character value and INTCK or any other function will treat it as such causing errors.

 

%LET START_DATE = '07-SEP-2022'D;
%LET END_DATE = '07-SEP-2022'D;

DATA _NULL_;
   DAYS_DIFF = INTCK('DAY', &START_DATE, &END_DATE);
   put days_diff=;
RUN;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 7 replies
  • 1190 views
  • 4 likes
  • 4 in conversation