<?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: Delete loop that contain not enough data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305043#M60880</link>
    <description>&lt;P&gt;It is easy if one row correspond to one month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='/folders/myfolders/Result IBM MSFT AAPL 1985 R2.xlsx' out=have dbms=xlsx replace;run;
data have;
 set have;
 by cusip;
 if first.cusip then n=0;
 n+1;
run;
proc sql;
create table want as
select *,
case 
when 
(select count(*) from have where cusip=a.cusip and n between a.n-35 and a.n) lt 36 then .
else 
(select mean(nvalue1) from have where cusip=a.cusip and n between a.n-35 and a.n) lt 36 
end as want_return
from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 Oct 2016 10:58:52 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-10-17T10:58:52Z</dc:date>
    <item>
      <title>Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304969#M60872</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I&amp;nbsp;have a date variable from 1926/01/01 to 2013/12/31. And stock returns for monthly. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to do is that use 36 month as a rolling window. Use full 36 month's returns to calculate a new variable and merge that variable as the next month's date after 36 month window.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did use CROSS JOIN to create different loops which contain 36 month data. But I only want to use only stocks which have a complete return history over 36 months, so please tell me how to delete stocks that do not have enough this data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 03:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304969#M60872</guid>
      <dc:creator>yotsuba88</dc:creator>
      <dc:date>2016-10-17T03:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304975#M60873</link>
      <description>&lt;P&gt;I think CASE... END clause can do that. Can you post your data and output ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;..................&lt;/P&gt;
&lt;P&gt;case&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when intck('month',&lt;/P&gt;
&lt;P&gt;( &amp;nbsp;select min(date) from &amp;nbsp; &lt;SPAN&gt; have where id=a.id and&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;date between intnx('month',a.date,-36,'s') and a.date&amp;nbsp;&lt;/SPAN&gt; )&lt;/P&gt;
&lt;P&gt;,a.date,'c') &amp;lt; 36&lt;/P&gt;
&lt;P&gt;then .&lt;/P&gt;
&lt;P&gt;else&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(select mean(return) from have where id=a.id and date between intnx('month',a.date,-36,'s') and a.date)&lt;/P&gt;
&lt;P&gt;end as want_return&lt;/P&gt;
&lt;P&gt;from have as a&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 03:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304975#M60873</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-17T03:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304979#M60874</link>
      <description>&lt;P&gt;Thank you for your reply. I have tried to upload my sas file but it cannot work. I upload my excel file with just 3 companies since 1985 here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 06:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304979#M60874</guid>
      <dc:creator>yotsuba88</dc:creator>
      <dc:date>2016-10-17T06:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304981#M60875</link>
      <description>&lt;P&gt;It's probably easier to create a count first of each ticker and then filter out those with the missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simulate&amp;nbsp;your data with 5 points and include it directly in the post.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you saying any ticker missing data for a specific period should be excluded? Have you looked at the ETS procedures - TIMESERIES and EXPAND?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 06:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304981#M60875</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-17T06:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304982#M60876</link>
      <description>&lt;P&gt;Please DO NOT post data in MS Officer files. For many of the contributors here, their organization's firewall will block such files because of security reasons, and the others won't open them because of said security reasons.&lt;/P&gt;
&lt;P&gt;Please post example data in a data step with datalines: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;How to create a data step version of your data AKA generate sample data for forums&lt;/A&gt;&lt;/P&gt;
&lt;TABLE cellspacing="0" border="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD align="left" height="32"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 17 Oct 2016 06:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/304982#M60876</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-17T06:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305006#M60877</link>
      <description>&lt;P&gt;Assume data is sorted by date, assign a &lt;STRONG&gt;new variable&lt;/STRONG&gt; for first occurence of a month to 1 otherwize to 0,&lt;/P&gt;
&lt;P&gt;then filter&amp;nbsp;those with sum(variable) &amp;lt; 36.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 08:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305006#M60877</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-17T08:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305022#M60879</link>
      <description>&lt;P&gt;Hi KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your warnings. I am new leaner&amp;nbsp;as well as new member so I will pay attention next time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 09:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305022#M60879</guid>
      <dc:creator>yotsuba88</dc:creator>
      <dc:date>2016-10-17T09:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305043#M60880</link>
      <description>&lt;P&gt;It is easy if one row correspond to one month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='/folders/myfolders/Result IBM MSFT AAPL 1985 R2.xlsx' out=have dbms=xlsx replace;run;
data have;
 set have;
 by cusip;
 if first.cusip then n=0;
 n+1;
run;
proc sql;
create table want as
select *,
case 
when 
(select count(*) from have where cusip=a.cusip and n between a.n-35 and a.n) lt 36 then .
else 
(select mean(nvalue1) from have where cusip=a.cusip and n between a.n-35 and a.n) lt 36 
end as want_return
from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2016 10:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305043#M60880</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-17T10:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Delete loop that contain not enough data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305285#M60907</link>
      <description>&lt;P&gt;It works for me now. &amp;nbsp;I really appreciate it.&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 05:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Delete-loop-that-contain-not-enough-data/m-p/305285#M60907</guid>
      <dc:creator>yotsuba88</dc:creator>
      <dc:date>2016-10-18T05:00:10Z</dc:date>
    </item>
  </channel>
</rss>

