<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Can not get macro variable to resolve to correct value. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258221#M49696</link>
    <description>&lt;P&gt;I am reading a user input variable for the 2 digit abbreviation of a state.&amp;nbsp; I am testing the length of the variable to see if it is &amp;gt; 0 then I know the user entered a value, for example 'MD'.&amp;nbsp;The variable in my title line in the report would show 'MD'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the user does not enter a value and it is blank, in my code I am trying to set it to the value of 'ALL'.&amp;nbsp; If this prompt is left blank then the user wants to get results for all states.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro BuildWhereClause;
   %global where_clause;
   %let where_clause = ;

/* check prompt STATE for user entered values */
  %if %length(&amp;amp;STATE) &amp;gt; 0 %then %do ;        /* value entered in prompt */
      %let NEW_STATE = "&amp;amp;STATE";             /* wrap quotes around macro variable */
      %let where_clause = &amp;amp;where_clause AND UPCASE(t1.STATE) = UPCASE(&amp;amp;NEW_STATE); /* build where clause*/
  %end;
  %else %do;   &lt;BR /&gt;
      %let NEW_STATE = call %symput("&amp;amp;STATE","ALL ");
%mend;
%BuildWhereClause; 
&lt;/PRE&gt;
&lt;P&gt;The code runs, however my variables have these values when I do %put to display.&amp;nbsp; It is not executing the symput to resolve the variable with correct value&lt;/P&gt;
&lt;P&gt;STATE =&lt;/P&gt;
&lt;P&gt;WARNING: Apparent invocation of macro SYMPUT not resolved.&lt;/P&gt;
&lt;P&gt;NEW_STATE = call %symput("","ALL ")&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2016 15:16:23 GMT</pubDate>
    <dc:creator>ncsthbell</dc:creator>
    <dc:date>2016-03-22T15:16:23Z</dc:date>
    <item>
      <title>Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258221#M49696</link>
      <description>&lt;P&gt;I am reading a user input variable for the 2 digit abbreviation of a state.&amp;nbsp; I am testing the length of the variable to see if it is &amp;gt; 0 then I know the user entered a value, for example 'MD'.&amp;nbsp;The variable in my title line in the report would show 'MD'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the user does not enter a value and it is blank, in my code I am trying to set it to the value of 'ALL'.&amp;nbsp; If this prompt is left blank then the user wants to get results for all states.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro BuildWhereClause;
   %global where_clause;
   %let where_clause = ;

/* check prompt STATE for user entered values */
  %if %length(&amp;amp;STATE) &amp;gt; 0 %then %do ;        /* value entered in prompt */
      %let NEW_STATE = "&amp;amp;STATE";             /* wrap quotes around macro variable */
      %let where_clause = &amp;amp;where_clause AND UPCASE(t1.STATE) = UPCASE(&amp;amp;NEW_STATE); /* build where clause*/
  %end;
  %else %do;   &lt;BR /&gt;
      %let NEW_STATE = call %symput("&amp;amp;STATE","ALL ");
%mend;
%BuildWhereClause; 
&lt;/PRE&gt;
&lt;P&gt;The code runs, however my variables have these values when I do %put to display.&amp;nbsp; It is not executing the symput to resolve the variable with correct value&lt;/P&gt;
&lt;P&gt;STATE =&lt;/P&gt;
&lt;P&gt;WARNING: Apparent invocation of macro SYMPUT not resolved.&lt;/P&gt;
&lt;P&gt;NEW_STATE = call %symput("","ALL ")&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258221#M49696</guid>
      <dc:creator>ncsthbell</dc:creator>
      <dc:date>2016-03-22T15:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258225#M49697</link>
      <description>&lt;P&gt;Well, this statement:&lt;/P&gt;
&lt;PRE&gt;%let NEW_STATE = call %symput("&amp;amp;STATE","ALL ");&lt;/PRE&gt;
&lt;P&gt;Is incorrect to start with, you do not call a macro - % means its a macro. &amp;nbsp;So maybe you need call symput. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However the question has to be why do this at all? &amp;nbsp;If you show your actual code where you use it will be clearer, but it seems to me:&lt;/P&gt;
&lt;PRE&gt;from  ABC
where  AVAR=COALESCE("&amp;amp;STATE.","ALL");&lt;/PRE&gt;
&lt;P&gt;Should work fine, i.e. if &amp;amp;STATE. is null then "ALL" will be used, otherwise &amp;amp;STATE. will be used. &amp;nbsp;As I always say, don't do your coding in macro, it is only there to generate code, Base SAS is the programming language to manipulate and process data!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258225#M49697</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-22T15:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258226#M49698</link>
      <description>&lt;P&gt;I do not have a lot of experience in SAS so the way you mentioned to do it in the 'where' clause with the functions, I have never used them before.&amp;nbsp; When there are SO many ways to do things in SAS, it's hard to know which is the best.&amp;nbsp; As I said, I don't have a lot of experience.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I removed the '%' from my call symput and it still did not resolve.&amp;nbsp;&amp;nbsp; I do not what to put this in my where clause because I have about 20 prompts, this is only one.&amp;nbsp; I have already written the code, this is the only peice I can't get to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for you suggestions.&amp;nbsp; I will take a look at trying this when I start the next project!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258226#M49698</guid>
      <dc:creator>ncsthbell</dc:creator>
      <dc:date>2016-03-22T15:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258233#M49701</link>
      <description>&lt;P&gt;You should be able to do it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%else %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %let NEW_STATE = "ALL ";&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear why you need quotes around "ALL" for this application, but that depends on what will be happening later with &amp;amp;NEW_STATE.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258233#M49701</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-22T15:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258238#M49704</link>
      <description>&lt;P&gt;Unfortunately if you don't know Base SAS - which is the programming language - I don't see how learning macro will help you. &amp;nbsp;Macro language's only purpose is to generate Base SAS code, it does nothing else. &amp;nbsp;It has nothing to do with which method is best, it all compiles to Base SAS code at the end of the day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This seems to work - note that in your code you are missing a %end:&lt;/P&gt;
&lt;PRE&gt;%macro BuildWhereClause;
  %global where_clause;
  %let where_clause=;
  %let new_state=abc;
  %let state=def;
  %if %length(&amp;amp;STATE.) &amp;gt; 0 %then %do;
      %let NEW_STATE = "&amp;amp;STATE.";
      %let where_clause=&amp;amp;where_clause. AND UPCASE(t1.STATE) = UPCASE(&amp;amp;NEW_STATE.);
  %end;
  %else %do;   
      %let NEW_STATE = call %symput("&amp;amp;STATE","ALL ");
  %end;
%mend;
%BuildWhereClause; 

%put &amp;amp;where_clause.;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258238#M49704</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-22T15:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258272#M49712</link>
      <description>&lt;P&gt;You cannot use &lt;FONT face="courier new,courier"&gt;call symput&lt;/FONT&gt; in macro code, as it is data step language. &lt;FONT face="courier new,courier"&gt;call symput&lt;/FONT&gt; is meant ONLY to set macro variables during data step runtime.&lt;BR /&gt;To set a macro variable, simply use %let (which is valid in macros and "open code")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to append to a macro variable, simply do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var = &amp;amp;var.xxxxxx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where xxxxxx is the text you want to append.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 17:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258272#M49712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-22T17:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get macro variable to resolve to correct value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258285#M49714</link>
      <description>&lt;P&gt;It might help to show the context of using this macro as well. Since you name it "BuildWhereClause" then I would expect it to make the appropriate where clause (even a blank one) for all of the expected inputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 17:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-not-get-macro-variable-to-resolve-to-correct-value/m-p/258285#M49714</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-22T17:35:07Z</dc:date>
    </item>
  </channel>
</rss>

