×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

Hi Katrin,
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)

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;

sasbuddy
http://sites.google.com/site/sasbuddy/
 

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

(OP)

Quote:

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

 



 

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

Hi Katrin,

I dont think that day values depends on settings.
You have proceed with your current consideration.

sasbuddy
http://sites.google.com/site/sasbuddy/
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close