Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fridays flag for each of 4 files (considering leap year) 1

Status
Not open for further replies.

katrina11

Technical User
Apr 30, 2011
108
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
 
weekday 6 denotes that its friday hence you can use following code

n = weekday(datepart(service_date)) ;
if n eq 6 then
flag = 1;
else flag = 0;
run;
Hi sasbuddy,
Thank you for the quick response. Does it means that n for Sunday would be 1? Then for Satuday n= 0?

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





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top