As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
Behavior difference on SAS Macro (SAS v8.2 VS SAS v9.2)
You may try executing the following sample programs on different SAS version. The result(Output value of Continue) from SAS v8.2 and SAS v9.2 is totally different.
%macro LocalInit(); %global Continue SameYear Empty; %let Continue=N; %let SameYear=Y; %let Empty=N; %mend; %macro SetContinueY(); %let Return=Y; data _null_; ans=upcase(symget('Return')); if ans = "Y" then call symput('Continue','Y'); run; %mend SetContinueY; %macro Main(); %LocalInit; %if &Empty=N and &SameYear=Y %then %SetContinueY; %end; %put Continue=&Continue; %mend; %Main;
(Output result: Continue=Y from SAS v8.2; Continue=N from SAS v9.2)
Any comments? Is it a bug in SAS v9.2?
- When I run this macro code in SAS 9.3, I get a syntax error message after the %END macro statement in the Main macro, which states:
- ERROR: There is no matching %DO statement for the %END. This statement will be ignored.
- Adding a %DO macro statement after %then results in Continue=Y appearing in the log.
- Perhaps the issue is that SAS v8.2 did not detect the syntax error of a missing %DO; statement, (or it wasn't required after the %then keyword), and this defect has now been corrected in SAS v9.2 and later. The revised Main macro code is
%macro Main(); %LocalInit; %if &Empty=N and &SameYear=Y %then %do; %SetContinueY; %end; %put Continue=&Continue; %mend;