<?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: Is there a way to take the difference of two rows to make one new row? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775404#M246479</link>
    <description>&lt;P&gt;First questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Why take _31 from _11?&lt;/LI&gt;
&lt;LI&gt;Why not _12 from _11, or _21 from _11?&lt;/LI&gt;
&lt;LI&gt;If none of the other rows are important then why are they there?&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Wed, 20 Oct 2021 13:31:48 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2021-10-20T13:31:48Z</dc:date>
    <item>
      <title>Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775402#M246478</link>
      <description>&lt;P&gt;I want to take the row where `ORD = _11` and subtract the row where `ORD = _31`, and store the difference in `ORD = _32`. So if `ORD = _32` then `A_CNT = 13-6 = 7` and `B_CNT = 17-4 = 13`. I know I could probably just transpose a few times, but I was wondering if difference between rows is possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Data Have*/
data have;
 input ORD $ A_CNT A_PCT B_CNT B_PCT;
 cards;
 _11	13	20	17	40
 _12	.	.	19	45
 _21	21	32	1	2
 _22	8	12	3	7
 _23	36	55	19	45
 _31	6	9	4	10
 ;
run;

/*Data Want: add ORD = _32*/
data have;
 input ORD $ A_CNT A_PCT B_CNT B_PCT;
 cards;
 _11	13	20	17	40
 _12	.	.	19	45
 _21	21	32	1	2
 _22	8	12	3	7
 _23	36	55	19	45
 _31	6	9	4	10
 _32	7	11	13	31
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 13:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775402#M246478</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-20T13:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775404#M246479</link>
      <description>&lt;P&gt;First questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Why take _31 from _11?&lt;/LI&gt;
&lt;LI&gt;Why not _12 from _11, or _21 from _11?&lt;/LI&gt;
&lt;LI&gt;If none of the other rows are important then why are they there?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 20 Oct 2021 13:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775404#M246479</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-10-20T13:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775405#M246480</link>
      <description>&lt;P&gt;I am trying to make a table. The ORD variable has formatting attached to it, where _11 is any subject with at least one hospital readmission, and _31 is any subject with at least one readmission due to a complication. I want _32 to be any subject with no readmission due to complications. The other rows are needed for the table.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 13:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775405#M246480</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-20T13:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775409#M246482</link>
      <description>&lt;P&gt;Use multiple set skill:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=tmp_:);
  set have;

  if _n_ = 1 then set have(where=(tmp_ord='_11') rename=(ord=tmp_ord a_cnt=tmp_a_cnt a_pct=tmp_a_pct b_cnt=tmp_b_cnt b_pct=tmp_b_pct));
  output;

  if ORD = '_31' then do;
    A_CNT = tmp_a_cnt - A_CNT ;
    A_PCT = tmp_a_pct - A_PCT;
    B_CNT = tmp_b_cnt - B_CNT;
    B_PCT = tmp_b_pct - B_PCT;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Oct 2021 14:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775409#M246482</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2021-10-20T14:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775449#M246497</link>
      <description>&lt;P&gt;I had no idea you could do a set within a set. Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, what does _N_ mean?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 17:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775449#M246497</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-20T17:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775451#M246498</link>
      <description>&lt;P&gt;_n_ is an &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1kfea7go1hi5qn1beilekqz6pf2.htm" target="_self"&gt;automatic variable&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xisDoc-argument"&gt;_N_&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;is initially set to 1. Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 20 Oct 2021 17:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775451#M246498</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-10-20T17:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to take the difference of two rows to make one new row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775454#M246500</link>
      <description>&lt;P&gt;Oh and I'll add, it's a common mistake to think that _n_ is the observation number in the input dataset.&lt;BR /&gt;They are not the same thing&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here's a simple example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;358  data have ;
359      do i=1 to 5 ;
360          output ;
361      end ;
362  run ;

NOTE: The data set WORK.HAVE has 5 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


363
364  data _null_ ;
365      set have (where=(i&amp;gt;2));
366      put _n_= i= ;
367  run ;

_N_=1 i=3
_N_=2 i=4
_N_=3 i=5
NOTE: There were 3 observations read from the data set WORK.HAVE.
      WHERE i&amp;gt;2;
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Oct 2021 17:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-take-the-difference-of-two-rows-to-make-one/m-p/775454#M246500</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-10-20T17:34:56Z</dc:date>
    </item>
  </channel>
</rss>

