BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FarazA_Qureshi
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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