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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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