Search code examples
sassas-macro

Assigning let variables to WHERE statement using DATA NULL


hi I am trying to use DATA NULL step to assign value to variable based on different criteria. This variable from NULL statement will be assigned to WHERE statement in the following DATA step.

Ideally if I run it today(Thursday which is 5) the code should return 30APR2019 for both the variables. But my code throws only the variable value in the LAST-IF- statement.

data _null_;

if weekday(today()) = 5 then do;
    %let exc_st_day = '30APR2019'd;
%let exc_en_day = '30APR2019'd;
end;

else if weekday(today()) = 6 then do;
%let exc_st_day = '01MAY2019'd;
%let exc_en_day = '01MAY2019'd;
end;

else if weekday(today()) = 2 then do;
%let exc_st_day = '02MAY2019'd;
%let exc_en_day = '02MAY2019'd;
end;

else if weekday(today()) = 3 then do;
%let exc_st_day = '03MAY2019'd;
%let exc_en_day = '03MAY2019'd;
end;

else if weekday(today()) = 4 then do;
%let exc_st_day = '04MAY2019'd;
%let exc_en_day = '06MAY2019'd;
end;

%put &exc_st_day &exc_en_day;

run;

Solution

  • You need to use CALL SYMPUTX() to create macro variables, not %LET within a data step.

    if weekday(today()) = 5 then do;
        call symputx('exc_st_day', '30APR2019'd);
        call symputx('exc_en_day', '30APR2019'd);
    end;