<?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 Re: SAS Query on macro and Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445067#M283075</link>
    <description>&lt;P&gt;You cannot use macro statements, like %IF, in an open code - neither in a data step nor in a sql code.&lt;/P&gt;
&lt;P&gt;You have to enclose it in a macro program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;macro&lt;/STRONG&gt; &lt;U&gt;macro_name&lt;/U&gt;(&amp;lt;any arguments&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.........&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if &amp;lt;any condition&amp;gt; %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.......&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.......&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; quit;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;mend&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%&lt;U&gt;macro_name&lt;/U&gt;(&amp;lt;supply arguments&amp;gt;);&lt;/P&gt;</description>
    <pubDate>Tue, 13 Mar 2018 07:15:35 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-03-13T07:15:35Z</dc:date>
    <item>
      <title>SAS Query on macro and Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445038#M283072</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I wanted to know how can we check whether a column is present in a table or not using macro?&amp;nbsp;&lt;/P&gt;&lt;P&gt;And i want to update that table if it is present in the table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I will have to use Proc SQL as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance, waiting for a quick reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 05:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445038#M283072</guid>
      <dc:creator>sarthakkataria</dc:creator>
      <dc:date>2018-03-13T05:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query on macro and Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445049#M283073</link>
      <description>&lt;P&gt;You can use next code in a macro program to check does variable exist in a table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let dsid=%sysfunc(open(table_in,i));
%let var_num=%sysfunc(varnum(&amp;amp;dsid,VARIABLE_NAME));
%if %eval(&amp;amp;VAR_num) = 0 %then %do;
     &amp;lt;variable does not exit&amp;gt;
%end;
%else do;
    &amp;lt;variable exists&amp;gt;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can even check it in a datastep:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_out;
  set table_in;
       dsid   =  open(table_in,i);
       var_num = varnum(dsid,'&amp;lt;variable name&amp;gt;');
       if var_num &amp;gt; 0 then do;
          &amp;lt;variable exists&amp;gt;
        end;
    ........
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Mar 2018 06:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445049#M283073</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-03-13T06:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query on macro and Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445063#M283074</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the code, but when I'm using Proc SQL fro updating the table, I am&amp;nbsp;getting some errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the following code, where employee is the name of my table and Emp_ID is one of the variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class="wmMessage_user_text_special"&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;%let dsid=%sysfunc(open(employee));&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;%let var_num=%sysfunc(varnum(&amp;amp;dsid,Emp_Add));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;%if %eval(&amp;amp;var_num) &amp;gt;0 %then %do;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;update employee as a&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;set Emp_ID = Emp_ID * 100;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;%else %do;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;select account_number from Employee_Salary&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="verdana, geneva"&gt;&lt;SPAN&gt;%quit;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It says %IF, %else are not valid in open code!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 07:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445063#M283074</guid>
      <dc:creator>sarthakkataria</dc:creator>
      <dc:date>2018-03-13T07:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query on macro and Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445067#M283075</link>
      <description>&lt;P&gt;You cannot use macro statements, like %IF, in an open code - neither in a data step nor in a sql code.&lt;/P&gt;
&lt;P&gt;You have to enclose it in a macro program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;macro&lt;/STRONG&gt; &lt;U&gt;macro_name&lt;/U&gt;(&amp;lt;any arguments&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.........&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if &amp;lt;any condition&amp;gt; %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.......&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.......&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; quit;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;mend&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%&lt;U&gt;macro_name&lt;/U&gt;(&amp;lt;supply arguments&amp;gt;);&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 07:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445067#M283075</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-03-13T07:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query on macro and Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445213#M283076</link>
      <description>Actually, from 9.4 M5 (or 4 documentation is not clear) you can use %IF in open code...but it seems that the OP is on an earlier release.</description>
      <pubDate>Tue, 13 Mar 2018 15:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query-on-macro-and-Proc-SQL/m-p/445213#M283076</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-13T15:52:46Z</dc:date>
    </item>
  </channel>
</rss>

