BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

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.

1 REPLY 1
Ksharp
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 655 views
  • 0 likes
  • 2 in conversation