Macro Variable Not Being Resolved

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Macro Variable Not Being Resolved

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) = 8) 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.


Accepted Solutions
Solution
‎10-21-2013 02:05 AM
Respected Advisor
Posts: 4,173

Re: Macro Variable Not Being Resolved

Posted in reply to FarazA_Qureshi

You need a "%global WhereClause;" in your macro else the macro variable has a scope of Local.

View solution in original post


All Replies
Solution
‎10-21-2013 02:05 AM
Respected Advisor
Posts: 4,173

Re: Macro Variable Not Being Resolved

Posted in reply to FarazA_Qureshi

You need a "%global WhereClause;" in your macro else the macro variable has a scope of Local.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 150 views
  • 0 likes
  • 2 in conversation