BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TeddoVanMierle
Obsidian | Level 7

Good afternoon, 

 

The goal is to substract the amount of holiday hours, from the hours_worked. 

 

When the amount of holidays hours are covering multiple days, the initial thought was using a DO UNTIL loop, IF THEN ELSE or using LAG.

 

But I only get it working using an extra dummy column per substracted day, which isn't efficient when e.g. someone has 120 hours.

 

The shown format is the format received from the data source.

 

What we try to achieve is: 

period     holiday      hours worked (8 per day)

9 feb       32            0

10 feb     24            0

11 feb     16            0

12 feb     8              0 

13 feb     0             8

 

TeddoVanMierle_1-1636314485009.png

 

Somebody any idea? 

 

Thanks in advance!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Do you try to get something like that:

data have;
period = '01feb2021'd +_N_; 
day = period;
format period yymmdd10. day downame.;
input holiday;
cards;
0
1
2
8
0
0
0
32
0
0
0
0
0
0
0
0
;
run;
proc print;
run;

data want;
  set have;

  holiday + holiday_tmp;

  hours_worked = 8 - holiday;
  label hours_worked = "hours worked (8 per day)";

  holiday_tmp = 0;
  if hours_worked<0 then
    do;
      hours_worked = 0;
      output;
      holiday_tmp + (holiday - 8);
    end;
  else output;

  drop holiday_tmp;
run;

proc print;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

What is the starting data set? If it is the first three columns of what you are showing, please say so clearly. We can't work from screen captures, so it would help if you could provide your starting data set as SAS data step code (instructions).


Can you explain what you want to happen with Feb 3 to Feb 5?

--
Paige Miller
yabwon
Onyx | Level 15

Do you try to get something like that:

data have;
period = '01feb2021'd +_N_; 
day = period;
format period yymmdd10. day downame.;
input holiday;
cards;
0
1
2
8
0
0
0
32
0
0
0
0
0
0
0
0
;
run;
proc print;
run;

data want;
  set have;

  holiday + holiday_tmp;

  hours_worked = 8 - holiday;
  label hours_worked = "hours worked (8 per day)";

  holiday_tmp = 0;
  if hours_worked<0 then
    do;
      hours_worked = 0;
      output;
      holiday_tmp + (holiday - 8);
    end;
  else output;

  drop holiday_tmp;
run;

proc print;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



TeddoVanMierle
Obsidian | Level 7

Hi Bart,

 

Thank you very much! This is exactly the solution we where looking for. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 363 views
  • 0 likes
  • 3 in conversation