Reputation: 33
I'm trying to use the call symput below to grab the most recent Friday and Sunday from the previous week. For example, if I run it today (5/17/2016) then it should grab 5/13/2016 and 5/15/2016. However, I'm getting strange results. The first time I run this piece of code, it results in no dates, or it results in 5/6/2016 and 5/8/2016. If I immediately run the same piece of code again then it provides the correct dates. This happens every time I open a new SAS session. Not sure what I am doing wrong. Any help would be appreciated...
data _null_;
%global beg end;
call symput ('beg',"'"||put(intnx('week.6',date(),-0,'b'),mmddyy10.)||"'");
call symput ('end',"'"||put(intnx('week.1',date(),-0,'b'),mmddyy10.)||"'");
put &beg;
put &end;
run;
Upvotes: 2
Views: 950
Reputation: 1120
Robert's comment below does a good job explaining what is going on here:
It's more to do with understanding how the macro pre-processor works. Basic rule of thumb is don't try and access macro variables in the same datastep they were created when using symput. If you absolutely have to you can get around this by using symget
A similar example is discussed towards the middle of this page; control+f "Resolving Macro Resolution Problems Occurring During DATA Step Compilation"). And the following code should fix your issue!
%global beg end;
data _null_;
call symput ('beg',"'"||put(intnx('week.6',date(),-0,'b'),mmddyy10.)||"'");
call symput ('end',"'"||put(intnx('week.1',date(),-0,'b'),mmddyy10.)||"'");
run;
data _null_;
put &beg.;
put &end.;
run;
Upvotes: 2
Reputation: 9109
You should use %PUT after the RUN to see the values of the macro variables BEG and END. No need for extra data step.
%put NOTE: &=BEG &=END;
Upvotes: -1