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
DATA _NULL_;
DAYS_DIFF = INTCK('DAY', input(&START_DATE, date11.), input(&END_DATE, date11.));
PUT DAYS_DIFF;
RUN;
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;
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';
DATA _NULL_;
DAYS_DIFF = INTCK('DAY', input(&START_DATE, date11.), input(&END_DATE, date11.));
PUT DAYS_DIFF;
RUN;
Thank you for your help. it worked/
@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;
Thanks a lot. it worked!
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;
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!
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.