<?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 Get one row per ID and calculated for each ID metrics between rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578981#M164292</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have 3 rows for each ID.&lt;/P&gt;
&lt;P&gt;I need to create a table that have 1 row for each ID with following information:&lt;/P&gt;
&lt;P&gt;From field "GK" will take the value in first row&lt;/P&gt;
&lt;P&gt;From&amp;nbsp; field "W" will take the accumulated value in all rows of ID&lt;/P&gt;
&lt;P&gt;From Field&amp;nbsp; "W" will take the accumulated value in all rows&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From&amp;nbsp; field "Y" will take the difference between last row and first row&lt;/P&gt;
&lt;P&gt;Desired output will be:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;GK_First&amp;nbsp; &amp;nbsp;Accum_W_Per_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;Accum_W_All&amp;nbsp; &amp;nbsp; &amp;nbsp; Y_Diff_Last_First&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
input ID mon x w y ;
cards;
1 1812 7 10 2
1 1903 8 15 3
1 1906 8 5  5
2 1812 10 7 4
2 1903 10 8 8
2 1906 9  5 9
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 04 Aug 2019 09:23:24 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-08-04T09:23:24Z</dc:date>
    <item>
      <title>Get one row per ID and calculated for each ID metrics between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578981#M164292</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have 3 rows for each ID.&lt;/P&gt;
&lt;P&gt;I need to create a table that have 1 row for each ID with following information:&lt;/P&gt;
&lt;P&gt;From field "GK" will take the value in first row&lt;/P&gt;
&lt;P&gt;From&amp;nbsp; field "W" will take the accumulated value in all rows of ID&lt;/P&gt;
&lt;P&gt;From Field&amp;nbsp; "W" will take the accumulated value in all rows&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From&amp;nbsp; field "Y" will take the difference between last row and first row&lt;/P&gt;
&lt;P&gt;Desired output will be:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp;GK_First&amp;nbsp; &amp;nbsp;Accum_W_Per_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;Accum_W_All&amp;nbsp; &amp;nbsp; &amp;nbsp; Y_Diff_Last_First&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
input ID mon x w y ;
cards;
1 1812 7 10 2
1 1903 8 15 3
1 1906 8 5  5
2 1812 10 7 4
2 1903 10 8 8
2 1906 9  5 9
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Aug 2019 09:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578981#M164292</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-04T09:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get one row per ID and calculated for each ID metrics between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578984#M164293</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bbb;
    set aaa;
    by id;
    if first.id then first=1; else first=0;
    if last.id then last=1; else last=0;
    y1=y;
run;

proc summary data=bbb;
    class id;
    var x/weight=first;
    var y/weight=first;
    var y1/weight=last;
    var w;
    output out=ccc sum=;
run;

data want;
    if _n_=1 then set ccc(where=(_type_=0) keep=w _type_ rename=(w=accum_w_all));
    set ccc(where=(_type_=1));
    gk_first=x;
    accum_w_id=w;
    y_diff_last_first=y1-y;
    drop w x y y1 _freq_ _type_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Aug 2019 11:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578984#M164293</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-04T11:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get one row per ID and calculated for each ID metrics between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578987#M164296</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
input ID mon x w y ;
cards;
1 1812 7 10 2
1 1903 8 15 3
1 1906 8 5  5
2 1812 10 7 4
2 1903 10 8 8
2 1906 9  5 9
;
run;
data temp;
 set aaa;
 by id;
 retain GK_First y_first;
 if first.id then do; GK_First=x;y_first=y;Accum_W_Per_ID=0;end;
 Accum_W_Per_ID+w;
 if last.id then do; Y_Diff_Last_First=y-y_first;output;end;
 keep ID   GK_First   Accum_W_Per_ID       Y_Diff_Last_First ;
run;
proc sql;
create table want as
select *,sum(Accum_W_Per_ID) as Accum_W_All  
 from temp;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Aug 2019 12:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-one-row-per-ID-and-calculated-for-each-ID-metrics-between/m-p/578987#M164296</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-08-04T12:18:09Z</dc:date>
    </item>
  </channel>
</rss>

