<?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: Dataset - Require a variable to occur at least n times in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717040#M221716</link>
    <description>&lt;P&gt;Do you want two new data sets or one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There should be 30 occurences of CUSIP in the entire time range and not within each trade date, correct?&lt;/P&gt;</description>
    <pubDate>Fri, 05 Feb 2021 11:14:24 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-02-05T11:14:24Z</dc:date>
    <item>
      <title>Dataset - Require a variable to occur at least n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717026#M221707</link>
      <description>&lt;P&gt;I have a dataset of bond transactions and want each bond to occur at least 30 times during my time range. There is one variable that is unique for each bond (an CUSIP Id) that I should be able use to see if the bond occurs n times. In other words, from my (full) dataset I would like to create a new dataset that only contains bonds that trades n times. Additionally, from this new dataset, I would like to calculate the average daily bond price. Thus, I need to see how many times an bond is traded during one day, compute average price and create a new dataset with the average prices and only one "trade" per day.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone please help a beginner?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snip SAS.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54348i2450EE2BAAAC3DAE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Snip SAS.PNG" alt="Snip SAS.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 10:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717026#M221707</guid>
      <dc:creator>adamlvkvist</dc:creator>
      <dc:date>2021-02-05T10:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset - Require a variable to occur at least n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717040#M221716</link>
      <description>&lt;P&gt;Do you want two new data sets or one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There should be 30 occurences of CUSIP in the entire time range and not within each trade date, correct?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 11:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717040#M221716</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-05T11:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset - Require a variable to occur at least n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717042#M221718</link>
      <description>Two; the first reduces the full data set so each CUSIP occurs at least 30 times during the time range, the second data set reduces the first further so each CUSIP only "trades" once a day and the price is the average daily price.&lt;BR /&gt;&lt;BR /&gt;There should be 30 occurences of CUSIP in the entire time range and not within each trade date, correct? - Exactly! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 05 Feb 2021 11:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717042#M221718</guid>
      <dc:creator>adamlvkvist</dc:creator>
      <dc:date>2021-02-05T11:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset - Require a variable to occur at least n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717046#M221720</link>
      <description>&lt;P&gt;Ok. See if you can use this as a template. Since I don't have your data, I use SASHELP.STOCKS to create some example data. I create it so IBM, Microsoft are traded more than Intel.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   set sashelp.stocks;
   if stock in ('IBM', 'Microsoft') then do;
      output; output;
   end;
   else output;
run;

proc freq data = have;
   tables stock / nocum nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="snip.PNG" style="width: 225px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54350iB496CBF8551D833C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="snip.PNG" alt="snip.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in this example, I want at least 250 obs for a stock to include in the first data set (change this to 30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table one as
   select * from have
   group by stock
   having n(stock) &amp;gt; 250;
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, I use this to create averages for each date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data = one nway;
   class date;
   var close;
   output out = want(drop = _:) mean =;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 11:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Require-a-variable-to-occur-at-least-n-times/m-p/717046#M221720</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-05T11:42:47Z</dc:date>
    </item>
  </channel>
</rss>

