<?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: Refer the non-blank column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255091#M48714</link>
    <description>&lt;P&gt;Or still a bit shorter:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set temp;
pct_chng=coalesce(x4,x3,x2,x1)/x1-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, your PROC SQL approach would produce different results for observations with, say, x1=. and x2&amp;gt;., namely the change from the &lt;EM&gt;first non-missing&lt;/EM&gt; to the last non-missing value in (x1, x2, x3, x4). If this is what you want, you could define&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pct_chng=coalesce(x4,x3,x2,x1)/coalesce(of x1-x4)-1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either way, of course, you should be sure that the denominator cannot be zero or add code to handle this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Mar 2016 20:43:46 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-03-07T20:43:46Z</dc:date>
    <item>
      <title>Refer the non-blank column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255041#M48700</link>
      <description>&lt;P&gt;I am trying to calculate the percentage change between the values of first and last updated column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2218iFCC619019C54E8E0/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="PCTCHNG.png" title="PCTCHNG.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For eg. For the first row, it should be (89-85)/85. Second row - (74-79)/79 and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To solve it, i have transposed the data set and generate serial number against IDs and then pick variables based on the highest and smallest serial numbers to calculate % change. It seems i make it complex. There should be a simple way to calculate it.&amp;nbsp;&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 temp;
input ID x1-x4;
cards;
1 85 89 . .
2 79 75 74 .
3 80 82 86 85
;
run;

proc transpose data = temp out = temp2;
by ID;
var x1-x4;
run;

data temp3;
set temp2 (where = (COL1 ^= .));
retain Serial 0;
If first.ID then Serial = 1;
else Serial = Serial + 1;
by ID;
run;

proc sql noprint;
create table t2 as
select a.ID, a.COL1, b.COL1 as COL2, (a.COL1-b.COL1)/b.COL1 *100 as change
from temp3 a left join
(select ID, COL1 from temp3
group by ID
having serial = min(serial)) b
on a.ID = b.ID
group by a.ID
having serial = max(a.serial);
create table t3 as 
select * from temp a left join t2 b
on a.ID = b.ID;
quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 18:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255041#M48700</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-03-07T18:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Refer the non-blank column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255047#M48701</link>
      <description>&lt;P&gt;The simple change you mention in the text is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ID x1-x4;
pct_chng = (x2-x1)/x1;/* or multiply by 100 if you really need to but a Percent format may be more appropriate*/
cards;
1 85 89 . .
2 79 75 74 .
3 80 82 86 85
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure, but were you looking to find the smallest of changes if using x2, x3 and x4?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 18:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255047#M48701</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-07T18:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Refer the non-blank column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255050#M48702</link>
      <description>&lt;P&gt;I think this sort of simplification is entirely the right approach.&amp;nbsp; But I think your problem is marginally more complex:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lastval=x2;&lt;/P&gt;
&lt;P&gt;if x3 &amp;gt; . then lastval=x3;&lt;/P&gt;
&lt;P&gt;if x4 &amp;gt; . then lastval=x4;&lt;/P&gt;
&lt;P&gt;pct_change = (lastval - x1) / x1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's still a one-step process though.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 18:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255050#M48702</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-07T18:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Refer the non-blank column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255091#M48714</link>
      <description>&lt;P&gt;Or still a bit shorter:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set temp;
pct_chng=coalesce(x4,x3,x2,x1)/x1-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, your PROC SQL approach would produce different results for observations with, say, x1=. and x2&amp;gt;., namely the change from the &lt;EM&gt;first non-missing&lt;/EM&gt; to the last non-missing value in (x1, x2, x3, x4). If this is what you want, you could define&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pct_chng=coalesce(x4,x3,x2,x1)/coalesce(of x1-x4)-1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either way, of course, you should be sure that the denominator cannot be zero or add code to handle this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 20:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-the-non-blank-column/m-p/255091#M48714</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-07T20:43:46Z</dc:date>
    </item>
  </channel>
</rss>

