<?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: Proc SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71544#M20656</link>
    <description>It depends on what kind of ranges you are talking about. In SAS, "columns" are known as variables and "rows" observations. If you copy the formula down column-wise like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
A2: = Sheet1!A2 + Sheet2!A2&lt;BR /&gt;
A3: = Sheet1!A3 + Sheet2!A3&lt;BR /&gt;
A4: = Sheet1!A4 + Sheet2!A4&lt;BR /&gt;
...&lt;BR /&gt;
[/pre]&lt;BR /&gt;
then it is easy to do the similar processing in SAS. You just merge the datasets by unique id then create one new variable like below:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sheet1;&lt;BR /&gt;
  input id v1;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 11&lt;BR /&gt;
2 12&lt;BR /&gt;
3 13&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet2;&lt;BR /&gt;
  input id v2;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 21&lt;BR /&gt;
2 22&lt;BR /&gt;
3 23&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet3;&lt;BR /&gt;
  merge sheet1 sheet2;&lt;BR /&gt;
  by id;&lt;BR /&gt;
  v3 = v1 + v2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* check */&lt;BR /&gt;
proc print data=sheet3;&lt;BR /&gt;
run;&lt;BR /&gt;
/* on lst&lt;BR /&gt;
id  v1  v2   v3&lt;BR /&gt;
 1  11  21  32&lt;BR /&gt;
 2  12  22  34&lt;BR /&gt;
 3  13  23  36&lt;BR /&gt;
*/&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
On the other hand, if you copy the excel formula across like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
A2: = Sheet1!A2 + Sheet2!A2&lt;BR /&gt;
B2: = Sheet1!B2 + Sheet2!B2&lt;BR /&gt;
C2: = Sheet1!C2 + Sheet2!C2&lt;BR /&gt;
...&lt;BR /&gt;
[/pre]&lt;BR /&gt;
then this isn't as simple as before because we have multiple variables involved. However, there are many different things in SAS that make it easy to loop over variables as well, arrays being one. hth.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sheet4;&lt;BR /&gt;
  input id x1 x2 x3;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1 2 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet5;&lt;BR /&gt;
  input id y1 y2 y3;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 10 20 30&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet6;&lt;BR /&gt;
   merge sheet4 sheet5;&lt;BR /&gt;
   by id;&lt;BR /&gt;
   array xs{1:3} x1-x3;&lt;BR /&gt;
   array ys{1:3} y1-y3;&lt;BR /&gt;
   array zs{1:3} z1-z3;&lt;BR /&gt;
   do i = 1 to 3;&lt;BR /&gt;
      zs{i} = xs{i} + ys{i};&lt;BR /&gt;
   end;&lt;BR /&gt;
   drop i;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* check */&lt;BR /&gt;
proc print data=sheet6;&lt;BR /&gt;
  var id z1-z3;&lt;BR /&gt;
run;&lt;BR /&gt;
/* on lst&lt;BR /&gt;
id  z1  z2  z3&lt;BR /&gt;
 1  11  22  33&lt;BR /&gt;
*/&lt;BR /&gt;
[/pre]</description>
    <pubDate>Wed, 15 Sep 2010 02:21:12 GMT</pubDate>
    <dc:creator>chang_y_chung_hotmail_com</dc:creator>
    <dc:date>2010-09-15T02:21:12Z</dc:date>
    <item>
      <title>Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71542#M20654</link>
      <description>I'm trying to figure out how to do something in SAS that I'd regularly do in Excel, but can't work it out. &lt;BR /&gt;
&lt;BR /&gt;
Imagine you have two Excel sheets and you want to add the corresponding cells in a third sheet. The forumula for Sheet3 cell A2 might look like this: Sheet1!A2+Sheet2!A2. How could this be performed in SAS given two data sets, each containing many variables? Using Proc SQL, I can create one new variable at a time in the select statement but can't figure out a way to perform the calculations on the range of variables and to create a corresponding range of variables containing  the outcomes of the calculations in one quick statement.</description>
      <pubDate>Mon, 13 Sep 2010 15:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71542#M20654</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-13T15:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71543#M20655</link>
      <description>I don't think you can do this in "one quick statement" — at least not according to my definition of the word "quick". You could probably do this in a Macro do-loop within PROC SQL.&lt;BR /&gt;
&lt;BR /&gt;
Another possibility is to do this in a data step. In a data step, you can merge the two data sets together and then do lots of addition of corresponding columns of variables using ARRAYs. Not what I would call "quick", but it works.

Message was edited by: Paige</description>
      <pubDate>Mon, 13 Sep 2010 15:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71543#M20655</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2010-09-13T15:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71544#M20656</link>
      <description>It depends on what kind of ranges you are talking about. In SAS, "columns" are known as variables and "rows" observations. If you copy the formula down column-wise like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
A2: = Sheet1!A2 + Sheet2!A2&lt;BR /&gt;
A3: = Sheet1!A3 + Sheet2!A3&lt;BR /&gt;
A4: = Sheet1!A4 + Sheet2!A4&lt;BR /&gt;
...&lt;BR /&gt;
[/pre]&lt;BR /&gt;
then it is easy to do the similar processing in SAS. You just merge the datasets by unique id then create one new variable like below:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sheet1;&lt;BR /&gt;
  input id v1;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 11&lt;BR /&gt;
2 12&lt;BR /&gt;
3 13&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet2;&lt;BR /&gt;
  input id v2;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 21&lt;BR /&gt;
2 22&lt;BR /&gt;
3 23&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet3;&lt;BR /&gt;
  merge sheet1 sheet2;&lt;BR /&gt;
  by id;&lt;BR /&gt;
  v3 = v1 + v2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* check */&lt;BR /&gt;
proc print data=sheet3;&lt;BR /&gt;
run;&lt;BR /&gt;
/* on lst&lt;BR /&gt;
id  v1  v2   v3&lt;BR /&gt;
 1  11  21  32&lt;BR /&gt;
 2  12  22  34&lt;BR /&gt;
 3  13  23  36&lt;BR /&gt;
*/&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
On the other hand, if you copy the excel formula across like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
A2: = Sheet1!A2 + Sheet2!A2&lt;BR /&gt;
B2: = Sheet1!B2 + Sheet2!B2&lt;BR /&gt;
C2: = Sheet1!C2 + Sheet2!C2&lt;BR /&gt;
...&lt;BR /&gt;
[/pre]&lt;BR /&gt;
then this isn't as simple as before because we have multiple variables involved. However, there are many different things in SAS that make it easy to loop over variables as well, arrays being one. hth.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sheet4;&lt;BR /&gt;
  input id x1 x2 x3;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1 2 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet5;&lt;BR /&gt;
  input id y1 y2 y3;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 10 20 30&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data sheet6;&lt;BR /&gt;
   merge sheet4 sheet5;&lt;BR /&gt;
   by id;&lt;BR /&gt;
   array xs{1:3} x1-x3;&lt;BR /&gt;
   array ys{1:3} y1-y3;&lt;BR /&gt;
   array zs{1:3} z1-z3;&lt;BR /&gt;
   do i = 1 to 3;&lt;BR /&gt;
      zs{i} = xs{i} + ys{i};&lt;BR /&gt;
   end;&lt;BR /&gt;
   drop i;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* check */&lt;BR /&gt;
proc print data=sheet6;&lt;BR /&gt;
  var id z1-z3;&lt;BR /&gt;
run;&lt;BR /&gt;
/* on lst&lt;BR /&gt;
id  z1  z2  z3&lt;BR /&gt;
 1  11  22  33&lt;BR /&gt;
*/&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 15 Sep 2010 02:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL/m-p/71544#M20656</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-09-15T02:21:12Z</dc:date>
    </item>
  </channel>
</rss>

