<?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: Cross multiply all the variables related to an ID with all the variables of a related ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360244#M274646</link>
    <description>&lt;P&gt;Thank you for helping me. Your solution also works. You have a nice day!!&lt;/P&gt;</description>
    <pubDate>Sat, 20 May 2017 23:27:32 GMT</pubDate>
    <dc:creator>nazmul</dc:creator>
    <dc:date>2017-05-20T23:27:32Z</dc:date>
    <item>
      <title>Cross multiply all the variables related to an ID with all the variables of a related ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360233#M274643</link>
      <description>&lt;P&gt;Dear Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the following card data, I want to first identify the other IDs' having the same year in the related ID column. Then I also want to copy the value of var1 and var2 of the related ID in&amp;nbsp;Var1_R and&amp;nbsp;Var2_R columns. Then I will multiply&amp;nbsp;&lt;SPAN&gt;Var1 with&amp;nbsp;Var1_R and&amp;nbsp;Var2 with&amp;nbsp;Var2_R in the&amp;nbsp;Cross_Multiplication column and add the results. I just included two variables in the example. I have 45 variables, 3200 IDS and 45 years totaling 132230 observations in the original dataset. How Can I do it in SAS? I will really appreciate your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id year var1 var2;&lt;BR /&gt;cards;&lt;BR /&gt;1 1980 3 2&lt;BR /&gt;1 1990 5 2&lt;BR /&gt;1 2000 5 4&lt;BR /&gt;1 2010 9 7&lt;BR /&gt;2 1980 4 2&lt;BR /&gt;2 1990 8 5&lt;BR /&gt;2 2000 4 8&lt;BR /&gt;3 1990 2 3&lt;BR /&gt;3 2010 7 2&lt;BR /&gt;5 1990 1 1&lt;BR /&gt;5 2010 9 2&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My results should look like the following table:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8972i1441928EDF320C58/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Picture1.png" title="Picture1.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2017 21:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360233#M274643</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2017-05-20T21:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cross multiply all the variables related to an ID with all the variables of a related ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360238#M274644</link>
      <description>&lt;P&gt;Easy with proc sql:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  create table want as
    select a.*,
           b.id as Related_ID,
           b.var1 as Var1_R,
           b.var2 as Var2_R,
           b.var1*a.var1+b.var2*a.var2 as Cross_Multiplication
      from have a, have b
        where a.id ne b.id and
              a.year=b.year
          order by id,year
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2017 22:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360238#M274644</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-20T22:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cross multiply all the variables related to an ID with all the variables of a related ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360239#M274645</link>
      <description>&lt;P&gt;PROC SQL self-join might do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table have_linked as
    select a.*,
           b.id as related_id,
           b.var1 as var1_r,
           b.var2 as var2_r,
           sum(b.var1*a.var1,b.var2*a.var2) as cross_multiplication
      from have a,
           have b
        where a.year=b.year and
              a.id ne b.id
           order by a.id, year, b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 May 2017 22:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360239#M274645</guid>
      <dc:creator>SuzanneDorinski</dc:creator>
      <dc:date>2017-05-20T22:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cross multiply all the variables related to an ID with all the variables of a related ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360244#M274646</link>
      <description>&lt;P&gt;Thank you for helping me. Your solution also works. You have a nice day!!&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2017 23:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360244#M274646</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2017-05-20T23:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cross multiply all the variables related to an ID with all the variables of a related ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360245#M274647</link>
      <description>&lt;P&gt;Thank you sir. Your code solved my problem. You have a good day!!&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2017 23:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-multiply-all-the-variables-related-to-an-ID-with-all-the/m-p/360245#M274647</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2017-05-20T23:28:21Z</dc:date>
    </item>
  </channel>
</rss>

