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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 529 views
  • 0 likes
  • 2 in conversation