BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

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

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

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
  • 1 reply
  • 722 views
  • 0 likes
  • 2 in conversation