Fridays flag for each of 4 files (considering leap year)
Fridays flag for each of 4 files (considering leap year)
(OP)
Hello experts,
I wonder if you can help me with code...
I have 4 files:
File2008
File2009
File2010
File2011
and I need to set a field "FridayFlag" with value =1 for all fridays in each file.
Proc contents for the ServiceDate look like the following:
Variable Type Len Format Informat Label
ServiceDate Num 8 DATETIME22.3 DATETIME22.3 ServiceDateFrom
How can I do it considering the data type and format/informat (and leap years as well)?
Below is just an example of the output I need
(I do not know if it is a friday in the 1st record. Just to illustrate)
*****************************************************************
ServiceDate FridayFlag
02JAN2008:00:00:00.000 1
18NOV2008:00:00:00.000 o
22AUG2008:00:00:00.000 1
Thank you in advance,
Katrin
I wonder if you can help me with code...
I have 4 files:
File2008
File2009
File2010
File2011
and I need to set a field "FridayFlag" with value =1 for all fridays in each file.
Proc contents for the ServiceDate look like the following:
Variable Type Len Format Informat Label
ServiceDate Num 8 DATETIME22.3 DATETIME22.3 ServiceDateFrom
How can I do it considering the data type and format/informat (and leap years as well)?
Below is just an example of the output I need
(I do not know if it is a friday in the 1st record. Just to illustrate)
*****************************************************************
ServiceDate FridayFlag
02JAN2008:00:00:00.000 1
18NOV2008:00:00:00.000 o
22AUG2008:00:00:00.000 1
Thank you in advance,
Katrin
RE: Fridays flag for each of 4 files (considering leap year)
Use following function.
friday_flag = weekday(datepart(service_date)) ;
sasbuddy
http://sites.google.com/site/sasbuddy/
RE: Fridays flag for each of 4 files (considering leap year)
n = weekday(datepart(service_date)) ;
if n eq 6 then
flag = 1;
else flag = 0;
run;
sasbuddy
http://sites.google.com/site/sasbuddy/
RE: Fridays flag for each of 4 files (considering leap year)
If I would like to assign flag values for each weekdays would the following be correct?
data surgery_day;
set surgery;
n = weekday(datepart(ServiceDate)) ;
if n eq 6 then
WeekFlag = 5;
else if n eq 5 then
WeekFlag = 4;
else if n eq 4 then
WeekFlag = 3;
else if n eq 3 then
WeekFlag = 2;
else if n eq 2 then
WeekFlag = 1;
else if n eq 1 then
WeekFlag = 0;
else WeekFlag = -1 ;
run;
I just worry if starting n value somewhat depends on SAS settings (if any)...Does it?
Thank you again for your help!
Katrin
RE: Fridays flag for each of 4 files (considering leap year)
I dont think that day values depends on settings.
You have proceed with your current consideration.
sasbuddy
http://sites.google.com/site/sasbuddy/