Here is the correct version. The old version is the redirect only version of the script. ### BEGIN SCRIPT #### #!/usr/bin/perl ###### # --start, -s = The date you would like to start generating regressors #--end, -e = When to stop generating holiday regressros # --scope, -c = D, W for Daily or Weekly respectively (e.g. Does this week have a particular holiday) # --file, -f = Ummm where to write the output silly! # # **NOTE** The EOM holiday is "End of Month" for computer systems this may be important for # extra processing and what not. # # You may need to set yout TZ environment variable if the script cannot # determine your time zone from the system (e.g. SET TZ=CST ) ###### use Getopt::Long; use Date::Manip; use Spreadsheet::WriteExcel; use Calendar::Functions; use Date::Holidays::USFederal; #use Date::Holidays; use Set::Array; use POSIX qw/strftime/; use Time::Local; my @regressors = (); #my $holidays = Date::Holidays->new(countrycode => 'us'); $result = GetOptions ("start|s=s" => \$start, "end|e=s" => \$end, "scope|c=s" => \$scope, "file|f=s" => \$filename); open (OUTFILE, ">>$filename"); print "Generating Holiday Dummy Variables starting $start to $end generated by $scope. Output to $filename \n"; #print all the dates based on scope as a test $startDate=ParseDate(\$start); if (! $startDate) { print "Error in the date";exit; } $endDate= ParseDate($end); print OUTFILE "Start Date: ",UnixDate($startDate,"%m/%d/%Y"),"\n"; print OUTFILE "End Date: ",$end,"\n"; # print OUTFILE "Last Day in Month: ",UnixDate(ParseDate("last day in JAN 2004"),"%m/%d/%Y"),"\n"; print OUTFILE "Date,HLY-NewYear,HLY-MLK,HLY-PRES,HLY-MEMORIAL,HLY-J4,HLY-LABOR,HLY-COLUMBUS,HLY-VETS,HLY-THANKS,HLY-XMA S,HLY-ELECT,HLY-PATRIOT,EOM\n"; $baseDate=$startDate; if ($scope eq "d"){ while(Date_Cmp($baseDate,$endDate)<0) { print OUTFILE UnixDate($baseDate,"%m/%d/%Y"), ","; if(holidayCheck($baseDate) eq "New Year's Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Martin Luther King, Jr. Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Presidents' Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Memorial Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Independence Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Labor Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Columbus Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Veterans' Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Thanksgiving Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Christmas Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "Election Day"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "U.S. Patriot Day Unofficial Observation"){print OUTFILE "1,"} else {print OUTFILE "0,"}; if(holidayCheck($baseDate) eq "EOM"){print OUTFILE "1"} else {print OUTFILE "0"}; print OUTFILE "\n"; $baseDate=DateCalc($baseDate,"+1 day"); } } # END IF D if($scope eq "w") { while(Date_Cmp($baseDate,DateCalc($endDate,"+7 days"))<0) { print OUTFILE UnixDate($baseDate,"%m/%d/%Y"), ","; if( (holidayCheck(DateCalc($baseDate,"+0 days")) eq "New Year's Day") || (holidayCheck(DateCalc($baseDate,"+1 days")) eq "New Year's Day") || (holidayCheck(DateCalc($baseDate,"+2 days")) eq "New Year's Day") || (holidayCheck(DateCalc($baseDate,"+3 days")) eq "New Year's Day") || (holidayCheck(DateCalc($baseDate,"+4 days")) eq "New Year's Day") || (holidayCheck(DateCalc($baseDate,"+5 days")) eq "New Year's Day") || (holidayCheck(DateCalc($baseDate,"+6 days")) eq "New Year's Day") ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Martin Luther King, Jr. Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Martin Luther King, Jr. Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Martin Luther King, Jr. Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Martin Luther King, Jr. Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Martin Luther King, Jr. Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Martin Luther King, Jr. Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Martin Luther King, Jr. Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Presidents' Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Presidents' Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Presidents' Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Presidents' Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Presidents' Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Presidents' Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Presidents' Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Memorial Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Memorial Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Memorial Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Memorial Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Memorial Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Memorial Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Memorial Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Independence Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Independence Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Independence Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Independence Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Independence Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Independence Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Independence Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Labor Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Labor Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Labor Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Labor Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Labor Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Labor Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Labor Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Columbus Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Columbus Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Columbus Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Columbus Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Columbus Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Columbus Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Columbus Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Veterans' Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Veterans' Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Veterans' Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Veterans' Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Veterans' Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Veterans' Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Veterans' Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Thanksgiving Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Thanksgiving Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Thanksgiving Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Thanksgiving Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Thanksgiving Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Thanksgiving Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Thanksgiving Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Christmas Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Christmas Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Christmas Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Christmas Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Christmas Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Christmas Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Christmas Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "Election Day" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "Election Day" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "Election Day" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "Election Day" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "Election Day" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "Election Day" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "Election Day" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "U.S. Patriot Day Unofficial Observation" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "U.S. Patriot Day Unofficial Observation" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "U.S. Patriot Day Unofficial Observation" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "U.S. Patriot Day Unofficial Observation" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "U.S. Patriot Day Unofficial Observation" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "U.S. Patriot Day Unofficial Observation" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "U.S. Patriot Day Unofficial Observation" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; if( holidayCheck(DateCalc($baseDate,"+0 days")) eq "EOM" || holidayCheck(DateCalc($baseDate,"+1 days")) eq "EOM" || holidayCheck(DateCalc($baseDate,"+2 days")) eq "EOM" || holidayCheck(DateCalc($baseDate,"+3 days")) eq "EOM" || holidayCheck(DateCalc($baseDate,"+4 days")) eq "EOM" || holidayCheck(DateCalc($baseDate,"+5 days")) eq "EOM" || holidayCheck(DateCalc($baseDate,"+6 days")) eq "EOM" ){print OUTFILE "1,"} else {print OUTFILE "0,"}; print OUTFILE "\n"; $baseDate=DateCalc($baseDate,"+7 days"); } #end while } #end if w close (OUTFILE); sub holidayCheck { my $t = shift; my $y = UnixDate($t,"%Y"); my $m = UnixDate($t,"%m"); my $B = UnixDate($t,"%B"); my $d = UnixDate($t,"%d"); my $checkDate = "$m/$d/$y"; SWITCH: { $checkDate eq "01/01/$y" and do {return "New Year's Day";}; $checkDate eq UnixDate(ParseDate("3rd monday of january $y"),"%m/%d/%Y") and do {return "Martin Luther King, Jr. Day";}; $checkDate eq UnixDate(ParseDate("3rd monday of february $y"),"%m/%d/%Y") and do {return "Presidents' Day";}; $checkDate eq UnixDate(ParseDate("last monday of may $y"),"%m/%d/%Y") and do {return "Memorial Day";}; $checkDate eq "07/04/$y" and do {return "Independence Day";}; $checkDate eq UnixDate(ParseDate("first monday of september $y"),"%m/%d/%Y") and do {return "Labor Day";}; $checkDate eq UnixDate(ParseDate("second monday of october $y"),"%m/%d/%Y") and do {return "Columbus Day";}; $checkDate eq "11/11/$y" and do {return "Veterans' Day";}; $checkDate eq UnixDate(ParseDate("fourth thursday of november $y"),"%m/%d/%Y") and do {return "Thanksgiving Day";}; $checkDate eq "12/25/$y" and do {return "Christmas Day";}; $checkDate eq UnixDate(ParseDate("first tuesday of november $y"),"%m/%d/%Y") and do {return "Election Day";}; $checkDate eq "09/11/$y" and do {return "U.S. Patriot Day Unofficial Observation";}; $checkDate eq UnixDate(ParseDate("last day in $B $y"),"%m/%d/%Y") and do {return "EOM";}; } #END SELECT } sub first_sunday_of_calmonth { my $m = shift; my $y = shift; my $dow = strftime("%w", 0,0,0,1,$m-1,$y-1900); my $time = timelocal(0,0,0,1,$m-1,$y-1900); return $time - ($dow * 24 * 60 * 60); } #### END SCRIPT #### [[alternative HTML version deleted]]