<?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: fill down with the given numbers in the same order in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534333#M6302</link>
    <description>&lt;P&gt;A simple way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have&lt;/P&gt;
&lt;P&gt;hml_next = lag6(hml);&lt;/P&gt;
&lt;P&gt;smb_next = lag6(smb);&lt;/P&gt;
&lt;P&gt;if _n_ &amp;gt; 6 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;hml = hml_next;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;smb = smg_next;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop hml_next smb_next;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Feb 2019 21:01:02 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-10T21:01:02Z</dc:date>
    <item>
      <title>fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534323#M6299</link>
      <description>&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;permno&lt;/TD&gt;&lt;TD&gt;rtrn&lt;/TD&gt;&lt;TD&gt;HML&lt;/TD&gt;&lt;TD&gt;SMB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;0.01&lt;/TD&gt;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R&gt;&lt;TD&gt;984&lt;/TD&gt;&lt;TD&gt;0.11&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;984&lt;/TD&gt;&lt;TD&gt;0.005&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;984&lt;/TD&gt;&lt;TD&gt;0.004&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;712&lt;/TD&gt;&lt;TD&gt;0.006&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to fill the blank spaces by exactly same order from the above by using SMB and HML numbers. Can anyone help me?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 19:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534323#M6299</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2019-02-10T19:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534324#M6300</link>
      <description>&lt;P&gt;Can you show your desired result using your example data?&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 19:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534324#M6300</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-10T19:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534326#M6301</link>
      <description>&lt;P&gt;If I interpret your question correct, you can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input permno $ rtrn HML SMB;
infile datalines missover;
datalines;
123 0.01 0.02 1.2
123 0.014 1.4 3.5
123 0.008 2.1 0.08
354 0.023 3.4 1.69
354 -0.25 0.006 2.14
354 0.14 1.21 3.54
765 -0.007    
765 -0.0036    
765 0.032    
984 0.11    
984 0.005    
984 0.004    
712 0.006    
;

data want(drop=idx);
   set have;
   array a{6} _temporary_;
   array b{6} _temporary_;
   idx=sum(mod(_N_, 6),1);
   if _N_ le 6 then do;
      a[idx]=HML;
      b[idx]=SMB;
   end;
   else do;
      HML=a[idx];
      SMB=b[idx];
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Feb 2019 19:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534326#M6301</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-10T19:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534333#M6302</link>
      <description>&lt;P&gt;A simple way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have&lt;/P&gt;
&lt;P&gt;hml_next = lag6(hml);&lt;/P&gt;
&lt;P&gt;smb_next = lag6(smb);&lt;/P&gt;
&lt;P&gt;if _n_ &amp;gt; 6 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;hml = hml_next;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;smb = smg_next;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop hml_next smb_next;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 21:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534333#M6302</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-10T21:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534338#M6303</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input permno $ rtrn HML SMB;
infile datalines missover;
datalines;
123 0.01 0.02 1.2
123 0.014 1.4 3.5
123 0.008 2.1 0.08
354 0.023 3.4 1.69
354 -0.25 0.006 2.14
354 0.14 1.21 3.54
765 -0.007    
765 -0.0036    
765 0.032    
984 0.11    
984 0.005    
984 0.004    
712 0.006    
;
data want ;
If _n_=1 then do;
   declare hash H (ordered: "A") ;
   h.definekey  ("_n_") ;
   h.definedata ("HML","SMB") ;
   h.definedone () ;
   end;
set have;
if coalesce(HML,SMB)&amp;gt;. then do;n+1; h.add();end;
else do;
k= mod(_n_,n);
k=ifn(k=0,n,k);
h.find(key:k);
end;
drop n k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Feb 2019 21:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534338#M6303</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-10T21:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534342#M6305</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp; Obviously, it's unlikely we are aware of your experience in SAS but nonetheless the question/solutions can be thought of giving rise to many potential caveat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. what if the number of non missing is not 6, so lagN would not work and will require another pass&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. what if there are many more vars besides sml,hmb , this will lead to having many more temp arrays&lt;/P&gt;
&lt;P&gt;3. In essence that will also require the hash to loop through definedata when _n_ =1 while instantiating the hash object but still straight forward.&lt;/P&gt;
&lt;P&gt;4. You could probably do for by groups unlike all for the reason associated permno will make it more meningful&lt;/P&gt;
&lt;P&gt;5. If you are into heavy data analysis and not necessarily coding, the same question can be turned to a very complex one--(all the more fun for us)&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 22:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534342#M6305</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-10T22:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: fill down with the given numbers in the same order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534344#M6306</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;BR /&gt;Thank you for your comment. Actually, the code I got from draycut worked nicely in my data set. I actually had more variables and more numbers but I made all the adjustments. I have huge data set which I can't use here.</description>
      <pubDate>Sun, 10 Feb 2019 22:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/fill-down-with-the-given-numbers-in-the-same-order/m-p/534344#M6306</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2019-02-10T22:10:23Z</dc:date>
    </item>
  </channel>
</rss>

