<?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 how to find macro variable value created by proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502220#M134036</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;In the below program how to find the value in the macro variable '&amp;amp;col" created by proc sql.&amp;nbsp; &amp;nbsp; &amp;nbsp;why this statement&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(&amp;amp;col, "A") eq 0 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;in&amp;nbsp; the below data step giving me errors.&amp;nbsp; &amp;nbsp;If I use the same data&amp;nbsp; step in the macro i am getting missing values for variable "A" .&amp;nbsp; Please suggest how to avoid "A"&amp;nbsp; variable values not to set missing. Thank you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data one;
input a $ b $ c;
datalines;
a b 1
c d 2
;

proc sql noprint;

   select distinct(name) into: col separated by "$" from sashelp.vcolumn where libname="WORK" and memname="ONE";
quit;

data one;
set one;
if index(&amp;amp;col, "A") eq 0 then do;
A=" ";
end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro col;&lt;BR /&gt;data one;&lt;BR /&gt;set one;&lt;BR /&gt;%if %index(&amp;amp;col, "A") eq 0 %then %do;&lt;BR /&gt;A=" ";&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%col;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Oct 2018 07:10:03 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2018-10-07T07:10:03Z</dc:date>
    <item>
      <title>how to find macro variable value created by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502220#M134036</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;In the below program how to find the value in the macro variable '&amp;amp;col" created by proc sql.&amp;nbsp; &amp;nbsp; &amp;nbsp;why this statement&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(&amp;amp;col, "A") eq 0 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;in&amp;nbsp; the below data step giving me errors.&amp;nbsp; &amp;nbsp;If I use the same data&amp;nbsp; step in the macro i am getting missing values for variable "A" .&amp;nbsp; Please suggest how to avoid "A"&amp;nbsp; variable values not to set missing. Thank you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data one;
input a $ b $ c;
datalines;
a b 1
c d 2
;

proc sql noprint;

   select distinct(name) into: col separated by "$" from sashelp.vcolumn where libname="WORK" and memname="ONE";
quit;

data one;
set one;
if index(&amp;amp;col, "A") eq 0 then do;
A=" ";
end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro col;&lt;BR /&gt;data one;&lt;BR /&gt;set one;&lt;BR /&gt;%if %index(&amp;amp;col, "A") eq 0 %then %do;&lt;BR /&gt;A=" ";&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%col;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 07:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502220#M134036</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-10-07T07:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to find macro variable value created by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502222#M134038</link>
      <description>&lt;P&gt;Use double quotes around &amp;amp;col.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 07:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502222#M134038</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-07T07:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to find macro variable value created by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502281#M134066</link>
      <description>&lt;P&gt;The value of the macro variable just replaces the reference and the resulting program statement is then evaluated.&lt;/P&gt;
&lt;P&gt;So you made COL have a value like A$B$C.&lt;/P&gt;
&lt;P&gt;If you substitute that into your IF and %IF statements you get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(A$B$C, "A") eq 0 then do;
%if %index(A$B$C, "A") eq 0 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the IF statement is not valid since you cannot have a variable name with dollar signs in it.&amp;nbsp; And your data step only has the variables A,B and C anyway.&amp;nbsp; If you want to treat that as a character constant then your need to enclose it in quotes.&amp;nbsp; But note that&amp;nbsp; you&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;get false positives if some other name contains A as part of the name.&amp;nbsp; So you should use the INDEXW() function instead.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if indexw("A$B$C", "A","$") eq 0 then do;
if indexw("&amp;amp;col", "A","$") eq 0 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro %IF condition can never be true since your string, A$B$C does not contain the letter A with quotes around it. You could remove the quotes from around A, but then you might get false positives if some other name contains A as part of the name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to search for the name A in the list of names you could use something like this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %index($A$B$C$, $A$) eq 0 %then %do;
%if %index($&amp;amp;col$, $A$) eq 0 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 21:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-macro-variable-value-created-by-proc-sql/m-p/502281#M134066</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-07T21:54:49Z</dc:date>
    </item>
  </channel>
</rss>

