Hi friends,
While looking forward to modify and refine a former code I made a variable to be declared on conditions in the following code:
====
%LET Approach = 'CONTINUOUS';
%LET YrBeg = 2007;
%LET YrEnd = 2013;
%LET MnBeg = 1;
%LET MnEnd = 9;
%LET MajDB = FAQ_NF.ConsNFData;
%LET WhereClauseA = MIS_MONTH BETWEEN MDY(&MnBeg,1,&YrBeg) AND INTNX("MONTH",MDY(&MnEnd,1,&YrEnd),0,"END");
%LET WhereClauseB = (YEAR(MIS_MONTH) = 2007 AND MONTH(MIS_MONTH) = 😎 OR (YEAR(MIS_MONTH) = 2008 AND MONTH(MIS_MONTH) = 9);
%LET WhereClauseC = AND ((UPPER(PRODUCT) = "AUTOS") AND (UPPER(PRODUCT_DESC) = "CAF")) OR
((UPPER(PRODUCT) = "AUTOS") AND (UPPER(PRODUCT_DESC) NE "CAF")) OR (UPPER(PRODUCT) = "SBL") OR
(UPPER(PRODUCT) = "PIL") OR (UPPER(PRODUCT) = "SECURED") OR (UPPER(PRODUCT) = "UNSECURED");
LIBNAME FAQ_NF 'F:\eLab\SAS_Experiments\FAQ2';
%MACRO ForWhereCl;
%IF &Approach = 'CONTINUOUS' %THEN %LET WhereClause = WHERE &WhereClauseA &WhereClauseC;
%ELSE %LET WhereClause = WHERE &WhereClauseB &WhereClauseC;
%MEND;
%ForWhereCl;
PROC SQL;
CREATE TABLE NET_FLOWS AS SELECT
MIS_MONTH,
PRODUCT,
PRODUCT_DESC,
SUM(POS)/1000 AS TOTAL_OS,
COUNT(POS) AS COUNT_OS,
FROM &MajDB
&WhereClause
GROUP BY
MIS_MONTH,
PRODUCT,
PRODUCT_DESC;
QUIT;
====
However when I run it the warning Apparent symbolic reference WHERECLAUSE not resolved. is faced.
Any suggestion and advice in this regard shall be highly obliged.
Thanx in advance.
You need a "%global WhereClause;" in your macro else the macro variable has a scope of Local.
You need a "%global WhereClause;" in your macro else the macro variable has a scope of Local.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.