<?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 contrast sets of IDs, another question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82857#M256755</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a word, no. For each ID1, there is only one pair of ID2-ID3.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Jul 2013 22:15:28 GMT</pubDate>
    <dc:creator>NonSleeper</dc:creator>
    <dc:date>2013-07-17T22:15:28Z</dc:date>
    <item>
      <title>How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82854#M256752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The hypothetical data looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;input ID1 ID2 ID3 X Y;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51&lt;/P&gt;&lt;P&gt;11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21&amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 52&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 53&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 54&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea is: For each cluster of ID1, find equal values of ID2 and ID3. Then for each pair of equal values, calculate the difference between Y and X, where Y is taken from corresponding ID3 and X from ID2. For example, in the case ID1=12, we have one where ID2=24 and ID3=24. The difference then will be 55-1=54. The same applies for ID2=ID3=22 (diff = 54-43=11) and ID2=ID3=11 (diff=52-41=11).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There always exists pairs of equal ID2 and ID3 for each ID1. Plus, the pattern of missing and non-missing values of ID2 and ID3 is also in the style of this data; for each ID1, there will be always one missing and one non-missing of ID2 and ID3, whichever the case. That is, there will be no situation like this:&lt;/P&gt;&lt;P&gt;ID1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 47&amp;nbsp;&amp;nbsp;&amp;nbsp; 51&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 20:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82854#M256752</guid>
      <dc:creator>NonSleeper</dc:creator>
      <dc:date>2013-07-17T20:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82855#M256753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data Yvalues(keep=ID1 Id2 Id3 Y) Xvalues(Keep=ID1 ID2 ID3 X);&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;if missing(ID2)=1 then output Yvalues;&lt;/P&gt;&lt;P&gt;else output Xvalues;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table answer as&lt;/P&gt;&lt;P&gt;select xv.id1&lt;/P&gt;&lt;P&gt;,id2&lt;/P&gt;&lt;P&gt;,id3&lt;/P&gt;&lt;P&gt;,x&lt;/P&gt;&lt;P&gt;,y&lt;/P&gt;&lt;P&gt;,y-x as answer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from Xvalues xv&lt;/P&gt;&lt;P&gt;join Yvalues Yv on yv.id1=xv.id1 and yv.id3=xv.id2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Hope that helps. This only works specifically on the conditions you specified&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 20:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82855#M256753</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-07-17T20:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82856#M256754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For ID1=12, instead of 22-22-24-24 ( two different pairs), is there any chance that you have 22-22-22-22 (two same pairs)? and if you do, how do you want to proceed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 21:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82856#M256754</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-07-17T21:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82857#M256755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a word, no. For each ID1, there is only one pair of ID2-ID3.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 22:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82857#M256755</guid>
      <dc:creator>NonSleeper</dc:creator>
      <dc:date>2013-07-17T22:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82858#M256756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In that case, I think you already have your answer by &lt;A __default_attr="810872" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Update: or for a one step solution,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;input ID1 ID2 ID3 X Y;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;11 21 . 41 51&lt;/P&gt;&lt;P&gt;11 . 21 42 52&lt;/P&gt;&lt;P&gt;12 22 . 43 53&lt;/P&gt;&lt;P&gt;12 . 22 44 54&lt;/P&gt;&lt;P&gt;12 . 24 45 55&lt;/P&gt;&lt;P&gt;12 24 . 1 2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select *, y-x as dif as diff from temp (drop=id3 y where=(not missing(id2))) a,&lt;/P&gt;&lt;P&gt;temp(drop=id2 x where=(not missing(id3))) b&lt;/P&gt;&lt;P&gt;where a.id1=b.id1 &lt;/P&gt;&lt;P&gt;and a.id2=b.id3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 22:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82858#M256756</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-07-17T22:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82859#M256757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice. Glad I was on the right track.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, that is a crazy secondary sql pass Haikou! I didn't know you could do a multiple select with a where statement to join. Thanks for posting that&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 23:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82859#M256757</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-07-17T23:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82860#M256758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. I guess it's time to have some sql education. That seems to be the gold standard for sorts of question I've made.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 23:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82860#M256758</guid>
      <dc:creator>NonSleeper</dc:creator>
      <dc:date>2013-07-17T23:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82861#M256759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually you don't need sql at all for this question. Note that in my first query I split the data using a data step, and then I choose to merge the data using sql. It's just as efficient to simply use a merge statement to re-join the data (you have to re-name the columns).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, Hai.Kou's query is only one step, instead of the 4 you would need to merge the data. On large datasets however I think the merge might be more efficient since the join is joining every element together and then filtering it down. That is my guess tho, as I have never seen a sql query like this (I use sql server, which you can't do this type of query in).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But yeah, ANYTHING you can do in sql you can do in a number of data steps, sometimes the sql is just easier to write.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 23:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82861#M256759</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-07-17T23:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to contrast sets of IDs, another question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82862#M256760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recommended using dataset for your situation caring about order of obs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data temp;
input ID1 ID2 ID3 X Y;
datalines;
11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51
11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21&amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 52
12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 53
12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 54
12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55
12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2
;
run;
data want;
 merge temp(keep=id1 id2 x where=(id2 is not missing)) temp(keep=id3 y where=(id3 is not missing));
 dif=y-x;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 02:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-contrast-sets-of-IDs-another-question/m-p/82862#M256760</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-18T02:31:50Z</dc:date>
    </item>
  </channel>
</rss>

