<?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: Linear smoothing depending on missing values in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/696814#M37452</link>
    <description>Thank you ! That's exactly what I wanted (I just have to replace the array by the values I want, being var1-var5 in the example I gave).&lt;BR /&gt;Learned quite some tricks about data steps thanks to your answer.</description>
    <pubDate>Thu, 05 Nov 2020 10:03:59 GMT</pubDate>
    <dc:creator>freshap</dc:creator>
    <dc:date>2020-11-05T10:03:59Z</dc:date>
    <item>
      <title>Linear smoothing depending on missing values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695492#M37421</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I have this dataset :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1 var2 var3 maxvar;
datalines;
id1 . . 999 3
id2 . 10 10 3&lt;BR /&gt;id3 10 . . 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The . are what I called missing values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want that, whenever I finda missing value in var1-var3, I go and take the first non-missing value to the right and split it by the amount of columns I went through to find this value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To help myself doing so, I implemented a column that gives the column in which I can find the last non missing value : &lt;EM&gt;maxvar&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If maxvar=2, it means that var2 is the last non missing value of all vars (so var3, var4,... will be . )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess it will be more clear with an example : using the data set I typed above, here is the result that I would like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;maxvar&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;id3&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that witch this example I could do something like "if var1=. and var2&amp;lt;&amp;gt;. then var1=var2/2 and var2=var2/2" etc, but the problem is that the &lt;STRONG&gt;number of var colums is variable and can go up to 100 colums&lt;/STRONG&gt; !&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought of using array statement and lag function in a data step, but I'm not sure how to manage the variable amount of columns I'll have to go through.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't hesitate to ask if you want me to be more precise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 14:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695492#M37421</guid>
      <dc:creator>freshap</dc:creator>
      <dc:date>2020-10-30T14:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Linear smoothing depending on missing values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695505#M37422</link>
      <description>&lt;P&gt;Do all of the missing values start in the first column? If not, it seems that you would need&amp;nbsp;&lt;/P&gt;
&lt;P&gt;StartVar and EndVar rather than MaxVar.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 15:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695505#M37422</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-10-30T15:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Linear smoothing depending on missing values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695506#M37423</link>
      <description>&lt;P&gt;As the problem is currently stated, you can try to use arrays, similar to the following. I assume the MaxVar value for ID='id2' was supposed to be 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ var1 var2 var3 maxvar;
datalines;
id1 .  . 999 3
id2 .  10 10 2
id3 10 . . 1
;

data want;
set have;
array v[*] var1-var3;
amount = v[maxvar] / maxvar;
do i = 1 to maxvar;
   v[i] = amount;
end;
run;

proc print;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Oct 2020 15:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695506#M37423</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-10-30T15:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Linear smoothing depending on missing values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695521#M37424</link>
      <description>&lt;P&gt;No, maxvar is not 2 in id2. I understand why you think I mistyped 3 into 2 but it's really a 3, as the last non-missing value is 10 in var3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me give another exemple. If I had a row with var1-var6 such as :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;var5&lt;/TD&gt;&lt;TD&gt;var6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to have this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;var5&lt;/TD&gt;&lt;TD&gt;var6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And maxvar here would be 6. I mean, I'm not even sure if maxvar will be of any use but I've got it in my dataset so I was thinking about using it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some observations/rows will have like maxvar=60 where some maxvar=4, so I thought of stopping the process when exceeding maxvar&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 16:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695521#M37424</guid>
      <dc:creator>freshap</dc:creator>
      <dc:date>2020-10-30T16:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Linear smoothing depending on missing values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695630#M37428</link>
      <description>&lt;P&gt;Maybe this code could work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array v _numeric_;&lt;BR /&gt;n=1;&lt;BR /&gt;nmi=1; *non-missing value index;&lt;/P&gt;
&lt;P&gt;do i=1 to dim(v);&lt;/P&gt;
&lt;P&gt;if missing(v(i)) then&lt;BR /&gt;n=n+1;&lt;BR /&gt;else&lt;BR /&gt;do;&lt;/P&gt;
&lt;P&gt;do j=nmi to i;&lt;BR /&gt;v[j]=v[i]/n;&lt;BR /&gt;end;&lt;BR /&gt;n=1;&lt;BR /&gt;nmi=i+1;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;drop n nmi i j;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Oct 2020 09:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/695630#M37428</guid>
      <dc:creator>jarapoch</dc:creator>
      <dc:date>2020-10-31T09:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Linear smoothing depending on missing values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/696814#M37452</link>
      <description>Thank you ! That's exactly what I wanted (I just have to replace the array by the values I want, being var1-var5 in the example I gave).&lt;BR /&gt;Learned quite some tricks about data steps thanks to your answer.</description>
      <pubDate>Thu, 05 Nov 2020 10:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Linear-smoothing-depending-on-missing-values/m-p/696814#M37452</guid>
      <dc:creator>freshap</dc:creator>
      <dc:date>2020-11-05T10:03:59Z</dc:date>
    </item>
  </channel>
</rss>

