-1

I have two macro variables:

  • runasofdate with value '20190107'
  • process_weekend that will be either 'Y' or 'N'

Both macro variables are from an Excel config file and assigned using call symput.

Then I have a table with list of local holidays:

HOLIDAY_DESC  HOLIDAY_DATE
HOLIDAY1      20190101
HOLIDAY2      20190409
HOLIDAY3      20190418
HOLIDAY4      20190419
HOLIDAY5      20190501

I need help with coding a macro:

If &runasofdate is in the table HOLIDAY column HOLIDAY_DATE, then abort process
Else if &runasofdate falls on a weekend and the macro process_weekend is in 'N' then abort process
Else if &runasofdate falls on a weekend and the process_weekend ='Y' then call sas programs (via %include)
Else if &runasofdate falls on a weekday then call sas programs (via %include)

Richard
  • 25,390
  • 3
  • 25
  • 38
Recy
  • 11
  • 3
  • Wouldn't it be easier to create a table that has all the dates and the Y/N flag in that table? And then if the record is a run date, run the code? – Reeza Apr 17 '20 at 01:44
  • I only have like 22 rows in holiday. – Recy Apr 17 '20 at 02:18
  • How does that relate to what I said? – Reeza Apr 17 '20 at 02:48
  • How many rows are in the Excel file ? What does the Excel table look like ? How many tabs, or how is the Excel data imported ? Is the imported `RUNASOFDATE` value a string, number or a SAS date formatted value ? Is the `HOLIDAY_DATE` a string ? a number ? a SAS date value formatted as yymmdd10. ? Show the CODE where you do `CALL SYMPUT` – Richard Apr 17 '20 at 03:21

1 Answers1

0

You haven't provided enough information to help you out fully but this can help you get started.

data have;
    set holiday_date end=eof;
    retain flag 'Run';
    *for this comparison to be valid - make sure you have the same types in the comparison;

    if holiday_date=&runasofdate then
        flag='Abort';

    if eof and flag='Run' then
        do;

            if weekday(&runasofdate) in (1, 7) and &process_weekend='Y' then
                do;
                    call execute ('sas program here');
                end;
            else if weekday(&runasofdate) not in (1, 7) and &process_weekend='N' then
                do;
                end;
            else
                do;
                    call execute('sas program here');
                end;
        end;
run;

The macro appendix has some examples of conditional logic. https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716

Reeza
  • 20,510
  • 4
  • 21
  • 38
  • I got an error: 84 if weekday(&runasofdate) in (1, 7) and &process_weekend='Y' then _ 22 WARNING: Apparent symbolic reference PROCESS_WEEKEND not resolved. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. – Recy Apr 17 '20 at 02:19
  • You said you had a process_weekend macro variable but the code isn't finding it. I'd be surprised if this worked - its the idea but you're going to have to customize it. – Reeza Apr 17 '20 at 02:48