<?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: Store total number of records in a variable and select random sample in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78508#M22628</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Exactly what I needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your help and time!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Mar 2013 17:11:43 GMT</pubDate>
    <dc:creator>nicnad</dc:creator>
    <dc:date>2013-03-15T17:11:43Z</dc:date>
    <item>
      <title>Store total number of records in a variable and select random sample</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78504#M22624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to know how to store the number of records from a table in a variable and then based on that number select a random sample that is 10% of the size of the total number of records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I came up with so far. My source table is cq_alert.closed_alert_cust :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if 0 then set cq_alert.closed_alert_cust nobs=n;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call symput('nrows',trim(left(put(n,8.))));&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put nobs= int(&amp;amp;nrows/10); /* I'm trying to store 10% of my total number of records in variable nobs */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To illustrate this better, if my source table had 100 records, I would like to create a table with 10 random records from it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 16:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78504#M22624</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-03-15T16:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Store total number of records in a variable and select random sample</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78505#M22625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just use RATE=.1 with survelselect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; h;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; i = &lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;1&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;to&lt;/SPAN&gt; &lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;100&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;output&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;end&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;surveyselect&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=h &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;rate&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;.1&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=sample;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 16:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78505#M22625</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-03-15T16:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Store total number of records in a variable and select random sample</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78506#M22626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for the quick reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the seconds part of my question : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets says I have this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _NULL_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if 0 then set cq_alert.closed_alert_cust nobs=n;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; call symput('nrows',trim(left(put(n,8.))));&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; stop;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%put nobs= int(&amp;amp;nrows/10);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;How do I use the variable nobs in a normal data procedure?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 16:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78506#M22626</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-03-15T16:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Store total number of records in a variable and select random sample</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78507#M22627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could create a macro variable NOBS with %LET or you could create the variable in your data step and use it in code as &amp;amp;nobs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; nobs= &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%sysevalF&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(&amp;amp;nrows/10,INTEGER);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt; &lt;/DIV&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt; &lt;/DIV&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 17:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78507#M22627</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-03-15T17:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Store total number of records in a variable and select random sample</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78508#M22628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Exactly what I needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your help and time!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 17:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Store-total-number-of-records-in-a-variable-and-select-random/m-p/78508#M22628</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-03-15T17:11:43Z</dc:date>
    </item>
  </channel>
</rss>

