DATA WORK.HAVE;
INFILE DATALINES DELIMITER =',';
FORMAT Date YYMMDD10. ;
INPUT DATE YYMMDD10. X ;
CARDS;
2021-08-17,99,
2021-09-01,505,
2021-10-05,91,
2021-11-05,65,
2021-12-07,250,
2022-01-01,704,
2022-02-02,687,
2022-03-03,123,
2022-04-03,456,
2022-05-06,789,
2022-06-16,687,
2022-07-27,123,
2022-08-05,400,
2022-09-05,700,
2022-10-22,850,
2022-11-18,700,
2022-12-07,120,
2023-01-27,123,
2023-02-05,400,
2023-03-07,700,
2023-04-22,850,
2023-05-18,700,
2023-06-07,120,
;
RUN;
DATA have;
SET have;
row= _n_;
RUN;
DATA cond_1;
FORMAT today YYMMDD10.;
SET have;
row= _n_;
/*If today's date is... */
today = '15MAR2022'd;
/*Then these rows are the rows I want */
IF row >2 AND row < 9 THEN DO;
condition_1 = 'Yes';
OUTPUT;
END;
RUN;
DATA cond_2;
FORMAT today YYMMDD10.;
SET have;
row= _n_;
/*If today's date is... */
today = '15MAY2023'd;
/*Then these rows are the rows I want */
IF row >8 AND row < 22 THEN DO;
condition_2 = 'Yes';
OUTPUT;
END;
RUN;
How do I change a WHERE/ or IF THEN-condition depending on which date it is?
I have two conditions:
Condition 1
If today's date is between 1 st of JAN 2022 to 31 st of OCT 2022 = table contains data from
1 st of OCT 2021 (WHERE DATE >= ‘01OCT2021’d)
Condition 2
If today's date is greater than or equal to 1 st of NOV 2022 = table contains data within a period of 13 months
(WHERE DATE >= INTNX(‘month’, XXX, -13, ‘B’)
Se my example tables. I use variable row just to illustrate the rows I want.
... View more