Help using Base SAS procedures

Weekdays of a Month - Part 2

Reply
Frequent Contributor
Posts: 122

Weekdays of a Month - Part 2

Hello All,

I have a requirement where I have a dataset which has the  days a technician visits a customer.We are only considering weekdays(Mon-Fri).If a technician did not visit the a particular customer

on a weekday then I need to identify that and populate a  flag as "NO Visit".Is there any way to achive this based on the below example?

eg:  Customer_name   TechVist_day

           John                02JAN2012

           John                03JAN2012

           John                05JAN2012       

           John                06JAN2012

           John                09JAN2012

            Mary               02JAN2012

           Mary                03JAN2012

           Sam                03JAN2012

           Sam                04JAN2012                     

Requirement 1: From the above example I need to populate the flag as "NO Visit" for 04JAN2012 for the customer John and same with customer Sam for 02JAN2012.

Requirement 1 was met through the valuable inputs from LINLIN and ANDREAS_IDS.

Now I need to run the code on a monthly basis and based on the above example,the John's the last record's TechVist_day is 09JAN2012..I need to set the flag for all weekdays after 09JAN2012 till the end of the month(same for Mary 03JAN2012 and SAM 04JAN2012).Please share your thoughts.

Super User
Posts: 9,681

Re: Weekdays of a Month - Part 2

How about:

data have;
input Customer_name $  TechVist_day : date9.;
format  TechVist_day date9.;
cards;
           John                02JAN2012
           John                03JAN2012
           John                05JAN2012       
           John                06JAN2012
           John                09JAN2012
            Mary               02JAN2012
           Mary                03JAN2012
           Sam                03JAN2012
           Sam                04JAN2012   
;
run;
data want;
 set have;
 by Customer_name;
 output;
 if last.Customer_name then do;
  do TechVist_day=TechVist_day+1 to intnx('month',TechVist_day,0,'e');
   if weekday(TechVist_day) not in (1 7) then output;
  end;
end;
run;

Ksharp

Ask a Question
Discussion stats
  • 1 reply
  • 162 views
  • 0 likes
  • 2 in conversation