<?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: macro program help in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562848#M10796</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NOBS &amp;gt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; AND &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(EXIST(TEST)) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%THEN&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This statement doesn't work as you think it will. You probably think NOBS is some number that the macro processor understands, but it is not. NOBS inside this %IF statement is a text string of four letters, the first letter is N, the second letter is O, and so on; and so NOBS is not a number. Macros evaluate text in a certain way, and the text string NOBS is always greater than 0, so code 1 always results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you mean&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF &amp;amp;NOBS &amp;gt; 0 THEN ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so if &amp;amp;NOBS contains a number then you could test if that number is &amp;gt; 0, but nowhere have you defined what the value of &amp;amp;NOBS is, so as shown, this wouldn't work either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't state your objective — is it trying to execute one set of code if data set TEST exists and has more than 0 observations, and execute other code if either TEST doesn't exist or has zero observations?&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2019 14:10:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-05-31T14:10:45Z</dc:date>
    <item>
      <title>macro program help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562846#M10795</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table that sometimes is with records and sometimes no. Ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table name Test:&lt;/P&gt;&lt;P&gt;NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table name Test:&lt;/P&gt;&lt;P&gt;NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to do a Macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;TEST&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NOBS &amp;gt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; AND &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(EXIST(TEST)) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%THEN&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;CODE 1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%ELSE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;CODE 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;The problem is that even the table Test is empty or with register, the macro will always execute the code 1.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Do you know why? &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Tks a lot!!!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 14:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562846#M10795</guid>
      <dc:creator>Sk1_SAS</dc:creator>
      <dc:date>2019-05-31T14:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: macro program help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562848#M10796</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NOBS &amp;gt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; AND &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(EXIST(TEST)) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%THEN&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This statement doesn't work as you think it will. You probably think NOBS is some number that the macro processor understands, but it is not. NOBS inside this %IF statement is a text string of four letters, the first letter is N, the second letter is O, and so on; and so NOBS is not a number. Macros evaluate text in a certain way, and the text string NOBS is always greater than 0, so code 1 always results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you mean&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF &amp;amp;NOBS &amp;gt; 0 THEN ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so if &amp;amp;NOBS contains a number then you could test if that number is &amp;gt; 0, but nowhere have you defined what the value of &amp;amp;NOBS is, so as shown, this wouldn't work either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't state your objective — is it trying to execute one set of code if data set TEST exists and has more than 0 observations, and execute other code if either TEST doesn't exist or has zero observations?&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 14:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562848#M10796</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-31T14:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro program help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562851#M10797</link>
      <description>&lt;P&gt;perfect, thank you&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 14:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562851#M10797</guid>
      <dc:creator>Sk1_SAS</dc:creator>
      <dc:date>2019-05-31T14:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: macro program help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562856#M10800</link>
      <description>&lt;P&gt;You don't need to know how may obs just some/none.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   if eof then do;
      put 'NOTE: data set or subset has 0 obs';
      *Execute when data has 0 obs.;
      end;
   else do;
      *has obs;
      put 'NOTE: has obs';
      end;
   stop;
   set sashelp.class end=eof; where sex eq 'f';
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29919iAFD469D048A7B244/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 14:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562856#M10800</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-05-31T14:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro program help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562860#M10802</link>
      <description>&lt;P&gt;It appears that the user also wants to test if the data set exists in the first place, hence the %SYSFUNC(EXIST( )), the data step code fails if the data set does not exist.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 14:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-program-help/m-p/562860#M10802</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-31T14:27:24Z</dc:date>
    </item>
  </channel>
</rss>

