data have;
input DOW $ HOLIDAY_FLG $ DATE DATE9.;
FORMAT DATE DATE9.;
DATALINES;
MON Y 1JAN2018
TUE N 2JAN2018
WED N 3JAN2018
THU N 4JAN2018
FRI N 5JAN2018
SAT N 6JAN2018
notice that 1jan2018 is a holiday. If I encounter a holiday on a Monday I want to add a field called date_flg and say
MON Y 1JAN2018 4
TUE N 2JAN2018 2
WED N 3JAN2018 2
THU N 4JAN2018 2
FRI N 5JAN2018 2
;
RUN;
If Mon is a holiday I want the date_flg to equal 4, the remaining days of the week should equal 2
If Mon is NOT a holiday I want the date_flg to equal 3 and the remaining days of the week should equal 1
I tried the lag function without success. Essentially I am attempting to evaluate previous row and populate based on this. Any ideas
Like this?
data WANT;
retain MON_IS_HOL;
set HAVE;
if DOW = 'MON' then MON_IS_HOL=(HOLIDAY_FLG='Y');
if DOW = 'MON' then DATE_FLG=3+MON_IS_HOL;
else DATE_FLG=1+MON_IS_HOL;
run;
DOW | HOLIDAY_FLG | DATE | DATE_FLG |
---|---|---|---|
MON | Y | 01JAN2018 | 4 |
TUE | N | 02JAN2018 | 2 |
WED | N | 03JAN2018 | 2 |
THU | N | 04JAN2018 | 2 |
FRI | N | 05JAN2018 | 2 |
SAT | N | 06JAN2018 | 2 |
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.