<?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 Handling zero sample size in proc surveryselect in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864044#M341243</link>
    <description>&lt;P&gt;I have a macro that takes a random sample of a dataset at every run and outputs a table. For example, if the random sample size is 1000, and if the source table somehow has fewer than 1000 records, it takes all the records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _sampsize = &amp;lt;code that chooses a sample size based on rules&amp;gt;
proc surveyselect data=CAD.SOURCE&amp;nbsp;out=CAD.RAND_DEST
    method=srs sampsize=&amp;amp;_sampsize. selectall;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the _samplesize macro variable is for whatever reason, zero, the code breaks and says sampsize has to be a positive integer. What would be the best/most reliable way to proof this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would prefer to return an empty table if the sample size is zero. I guess I check against sample size first, but is there a more 'elegant' way?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 13:16:21 GMT</pubDate>
    <dc:creator>KJazem</dc:creator>
    <dc:date>2023-03-14T13:16:21Z</dc:date>
    <item>
      <title>Handling zero sample size in proc surveryselect</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864044#M341243</link>
      <description>&lt;P&gt;I have a macro that takes a random sample of a dataset at every run and outputs a table. For example, if the random sample size is 1000, and if the source table somehow has fewer than 1000 records, it takes all the records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _sampsize = &amp;lt;code that chooses a sample size based on rules&amp;gt;
proc surveyselect data=CAD.SOURCE&amp;nbsp;out=CAD.RAND_DEST
    method=srs sampsize=&amp;amp;_sampsize. selectall;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the _samplesize macro variable is for whatever reason, zero, the code breaks and says sampsize has to be a positive integer. What would be the best/most reliable way to proof this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would prefer to return an empty table if the sample size is zero. I guess I check against sample size first, but is there a more 'elegant' way?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864044#M341243</guid>
      <dc:creator>KJazem</dc:creator>
      <dc:date>2023-03-14T13:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Handling zero sample size in proc surveryselect</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864047#M341244</link>
      <description>&lt;P&gt;Just enhance your macro logic such that the PROC SURVEYSELECT with a zero sample size will never be executed.&lt;BR /&gt;You know how to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864047#M341244</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-03-14T13:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Handling zero sample size in proc surveryselect</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864049#M341246</link>
      <description>Yes, this is my first thought. But I would like to return an empty table instead. &lt;BR /&gt;&lt;BR /&gt;if &amp;amp;_sampsize. = 0 then do;&lt;BR /&gt;    data CAD.RAND_DEST;&lt;BR /&gt;        set CAD.SOURCE;&lt;BR /&gt;    run;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;Would this work? Each output table (random sample) will be appended to main table.</description>
      <pubDate>Tue, 14 Mar 2023 13:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864049#M341246</guid>
      <dc:creator>KJazem</dc:creator>
      <dc:date>2023-03-14T13:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Handling zero sample size in proc surveryselect</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864053#M341249</link>
      <description>&lt;P&gt;This would work :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;_sampsize. = 0 then do;
 data CAD.RAND_DEST;
  set CAD.SOURCE;
  IF 0; /* subsetting IF , but never true */
 run;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;DIV id="ConnectiveDocSignExtentionInstalled" data-extension-version="1.0.4"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Mar 2023 13:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864053#M341249</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-03-14T13:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Handling zero sample size in proc surveryselect</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864067#M341257</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432808"&gt;@KJazem&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, this is my first thought. But I would like to return an empty table instead. &lt;BR /&gt;&lt;BR /&gt;if &amp;amp;_sampsize. = 0 then do;&lt;BR /&gt;data CAD.RAND_DEST;&lt;BR /&gt;set CAD.SOURCE;&lt;BR /&gt;run;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;Would this work? Each output table (random sample) will be appended to main table.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the goal is to APPEND observations to a table and you want zero observations appended, then just skip the APPEND step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to generate a dataset with zero observations you could add a STOP statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CAD.RAND_DEST;
  stop;
  set CAD.SOURCE;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or the OBS=0 dataset option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CAD.RAND_DEST;
  set CAD.SOURCE (obs=0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 14:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-zero-sample-size-in-proc-surveryselect/m-p/864067#M341257</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-14T14:32:45Z</dc:date>
    </item>
  </channel>
</rss>

