<?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: assign a value to Macro variable when no rows were selected from table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144576#M28848</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When where returns no rows for a proc sql select statement&amp;nbsp; the procedure still sets the number of selected rows (0) in the SQLOBS macro var.&lt;/P&gt;&lt;P&gt;so use &amp;amp;sqlobs as that number of rows.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Mar 2014 17:44:32 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2014-03-14T17:44:32Z</dc:date>
    <item>
      <title>assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144571#M28843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Anyone has an idea how we can assign a value to Macro variable when no rows were selected below? Thanks for any inputs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select count into : macro_out&amp;amp;j from macro_out;&lt;/P&gt;&lt;P&gt;%put &amp;amp;&amp;amp;macro_out&amp;amp;j;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lei&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 16:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144571#M28843</guid>
      <dc:creator>jay_q</dc:creator>
      <dc:date>2014-03-14T16:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144572#M28844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Before the proc sql step, add:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let macro_out&amp;amp;j = /*whatever value you want iuf now rows are selected by SQL step*/&amp;nbsp; ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 16:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144572#M28844</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2014-03-14T16:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144573#M28845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Quentin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry I wasn't clear about the process. I have a do loop. After each loop, Count(*) from ABC table decreases until no values displayed.&amp;nbsp; My problem is when no values displayed, Macro variable &amp;amp;&amp;amp;macro_out&amp;amp;j would not get assigned and resolved.&amp;nbsp; So %if condition would generate error. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to 100;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;..............&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table macro_out as &lt;BR /&gt;(select exclude_ind,link_id,count(*)as count&lt;BR /&gt;from&amp;nbsp;&amp;nbsp; ABC&lt;/P&gt;&lt;P&gt;where&amp;nbsp; ind = 'N' &lt;BR /&gt;group&amp;nbsp; by 1,2 &lt;BR /&gt;having link_id is null);&lt;/P&gt;&lt;P&gt;select count into : macro_out&amp;amp;j from macro_out;&lt;BR /&gt;%put &amp;amp;&amp;amp;macro_out&amp;amp;j;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let con_exit2=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if &amp;amp;&amp;amp;macro_out&amp;amp;j = &amp;amp;con_exit2 %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %goto exit2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%exit2: &lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 16:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144573#M28845</guid>
      <dc:creator>jay_q</dc:creator>
      <dc:date>2014-03-14T16:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144574#M28846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Sticking with my original suggestion. : )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add&amp;nbsp; %let macro_out&amp;amp;j=0;&amp;nbsp;&amp;nbsp; before your SQL step&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the SQL step runs:&lt;/P&gt;&lt;P&gt;&amp;nbsp; if there are records in macro_out then count will be &amp;gt;0 and macro_out&amp;amp;j will be assigned the value of count.&lt;/P&gt;&lt;P&gt;&amp;nbsp; if there are no records in macro_out (because no records that satisfy the having clause), then select count into : macro_out&amp;amp;j will not execute.&amp;nbsp; And the value of macro_out&amp;amp;j will remain as 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I understand it. : )&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 17:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144574#M28846</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2014-03-14T17:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144575#M28847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As I understand your program, even if the number of rows of ABC has decreased to zero, your table macro_out&lt;/P&gt;&lt;P&gt;should have one row with count=0 and missing values for the other variabes, so your mv macro_out&amp;amp;j. should be valued.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your example, You are looping on i instead of j. Can this be the explanation ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can test the macrovariable &amp;amp;sqlobs. to check if your SQL request returned something.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 17:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144575#M28847</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2014-03-14T17:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144576#M28848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When where returns no rows for a proc sql select statement&amp;nbsp; the procedure still sets the number of selected rows (0) in the SQLOBS macro var.&lt;/P&gt;&lt;P&gt;so use &amp;amp;sqlobs as that number of rows.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 17:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144576#M28848</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-03-14T17:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: assign a value to Macro variable when no rows were selected from table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144577#M28849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Quentin!&lt;/P&gt;&lt;P&gt;Tested and sold!&lt;/P&gt;&lt;P&gt;Also, I found using %symexist() also solve my problem:)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*%if %symexist(macro_out&amp;amp;j)=0 %then %do;*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* %goto exit2;*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*%end;*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 17:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-a-value-to-Macro-variable-when-no-rows-were-selected-from/m-p/144577#M28849</guid>
      <dc:creator>jay_q</dc:creator>
      <dc:date>2014-03-14T17:56:37Z</dc:date>
    </item>
  </channel>
</rss>

