<?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: How to net a dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343217#M272917</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 format id1 id2 $30. value 8.;
 input id1 id2 value;
 datalines;
a b 10
a c 2
a d 6
b a 5
c a 3
c d 7
;
run;

data inter;
set have;
if id1 &amp;gt; id2
then do;
  x = id1;
  id1 = id2;
  id2 = x;
end;
drop x;
run;

proc sort data=inter;
by id1 id2 descending value;
run;

data want;
set inter;
by id1 id2;
oldval = lag(value);
if first.id2 and last.id2 then output;
else if not first.id2
then do;
  value = oldval - value;
  output;
end;
drop oldval;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates the values, but with a slightly different order of observations and ID's within the observations.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 09:50:23 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-03-22T09:50:23Z</dc:date>
    <item>
      <title>How to net a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343209#M272916</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have the following 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;
 format id1 id2 $30. value 8.;
 input id1 id2 value;
 datalines;
a	b	10
a	c	2
a	d	6
b	a	5
c	a	3
c	d	7
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I would like to get the following one:&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 want;
 format id1 id2 $30. value 8.;
 input id1 id2 value;
 datalines;
a	b	5
a	d	6
c	a	1
c	d	7
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;In practice&amp;nbsp;I have&lt;BR /&gt;- looked for non ordered couples across the first two rows,&lt;BR /&gt;- kept the couple such that the value is bigger,&lt;BR /&gt;- and assigned it the difference between values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be very much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 09:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343209#M272916</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-03-22T09:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to net a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343217#M272917</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 format id1 id2 $30. value 8.;
 input id1 id2 value;
 datalines;
a b 10
a c 2
a d 6
b a 5
c a 3
c d 7
;
run;

data inter;
set have;
if id1 &amp;gt; id2
then do;
  x = id1;
  id1 = id2;
  id2 = x;
end;
drop x;
run;

proc sort data=inter;
by id1 id2 descending value;
run;

data want;
set inter;
by id1 id2;
oldval = lag(value);
if first.id2 and last.id2 then output;
else if not first.id2
then do;
  value = oldval - value;
  output;
end;
drop oldval;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates the values, but with a slightly different order of observations and ID's within the observations.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 09:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343217#M272917</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-22T09:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to net a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343263#M272918</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the order of observations is not important, but&amp;nbsp;the order of IDs is&amp;nbsp;fundamental.&lt;/P&gt;&lt;P&gt;The pairs&amp;nbsp;that appears in the final dataset needs to be the one with higher value, that is the difference between the values of the two couples having the same elements has to be positive. In&amp;nbsp;the dataset Want that you suggested the value assigned to the pair (a c)&amp;nbsp;should be -1 rather than 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Furthermore, I cannot&amp;nbsp;not rely on "id1 &amp;gt; id2" as the id1 and id2 could be any string ($30).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 13:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343263#M272918</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-03-22T13:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to net a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343272#M272919</link>
      <description>&lt;P&gt;So I slightly changed the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inter;
set have;
length key $60;
if id1 &amp;gt; id2
then key = id2 !! id1;
else key = id1 !! id2;
run;

proc sort data=inter;
by key value;
run;

data want (keep=id1 id2 value);
set inter;
by key;
oldval = lag(value);
if first.key and last.key then output;
else if not first.key
then do;
  value = abs(oldval - value);
  output;
end;
drop oldval;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The id1 &amp;gt; id2 is just there to unify the creation of the key variable.&lt;/P&gt;
&lt;P&gt;If you somehow need to preserve the original order, we'd have to store _n_ in the data inter; step and sort the end result by that.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 13:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-net-a-dataset/m-p/343272#M272919</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-22T13:53:32Z</dc:date>
    </item>
  </channel>
</rss>

