<?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 proc sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58661#M16479</link>
    <description>Hello I'm a new user. &lt;BR /&gt;
&lt;BR /&gt;
I've created a number of tables labelled rr1 to rr120. I want to extract columns of data from each one, labelled pred1 to pred120 into one new data file. &lt;BR /&gt;
I decided the most efficient way to do this would be through the proc SQL function. &lt;BR /&gt;
&lt;BR /&gt;
What I'm struggling with is how to extract the data from the looping. If I insert the create table instruction within the loop it overwrites 120 times, whereas if I leave it out, I get the query results but no table creation. &lt;BR /&gt;
&lt;BR /&gt;
Any ideas on how this may be rectified?&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot. &lt;BR /&gt;
&lt;BR /&gt;
Tom&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro mergingdata;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create tables results as&lt;BR /&gt;
%do i = 1 %to 120;&lt;BR /&gt;
select date, pred&amp;amp;i&lt;BR /&gt;
from rr&amp;amp;i&lt;BR /&gt;
order by date; &lt;BR /&gt;
%end;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%mergingdata;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;</description>
    <pubDate>Wed, 17 Feb 2010 16:18:06 GMT</pubDate>
    <dc:creator>tomop</dc:creator>
    <dc:date>2010-02-17T16:18:06Z</dc:date>
    <item>
      <title>proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58661#M16479</link>
      <description>Hello I'm a new user. &lt;BR /&gt;
&lt;BR /&gt;
I've created a number of tables labelled rr1 to rr120. I want to extract columns of data from each one, labelled pred1 to pred120 into one new data file. &lt;BR /&gt;
I decided the most efficient way to do this would be through the proc SQL function. &lt;BR /&gt;
&lt;BR /&gt;
What I'm struggling with is how to extract the data from the looping. If I insert the create table instruction within the loop it overwrites 120 times, whereas if I leave it out, I get the query results but no table creation. &lt;BR /&gt;
&lt;BR /&gt;
Any ideas on how this may be rectified?&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot. &lt;BR /&gt;
&lt;BR /&gt;
Tom&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro mergingdata;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create tables results as&lt;BR /&gt;
%do i = 1 %to 120;&lt;BR /&gt;
select date, pred&amp;amp;i&lt;BR /&gt;
from rr&amp;amp;i&lt;BR /&gt;
order by date; &lt;BR /&gt;
%end;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%mergingdata;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;</description>
      <pubDate>Wed, 17 Feb 2010 16:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58661#M16479</guid>
      <dc:creator>tomop</dc:creator>
      <dc:date>2010-02-17T16:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58662#M16480</link>
      <description>Hi:&lt;BR /&gt;
  I'm a bit confused by your description of the data... You always want the DATE var and then&lt;BR /&gt;
Option 1:  from set RR1, you only want PRED1?? and from set RR2, you only want PRED2?? &lt;BR /&gt;
Option 2: Or, from set RR1 you want PRED1-PRED120??? and from set RR2 you want PRED1-PRED120???&lt;BR /&gt;
&lt;BR /&gt;
Do the datasets RR1-RR120 only have Date and one other variable each, or do the datasets RR1-RR120 each have Date and PRED1-PRED120????&lt;BR /&gt;
&lt;BR /&gt;
For your final dataset, you want:&lt;BR /&gt;
DATE PRED1-PRED120 in an output file called RESULTS??&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 17 Feb 2010 16:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58662#M16480</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-02-17T16:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58663#M16481</link>
      <description>Hello, &lt;BR /&gt;
&lt;BR /&gt;
Option 1. From RR1 I want the variable pred1, from RR2 I want the variable pred2 etc.. through to 120. &lt;BR /&gt;
&lt;BR /&gt;
The data sets RR1, have about 120 variables stored inside them, each has a date, but the remainder of the 120 varibles are different. &lt;BR /&gt;
&lt;BR /&gt;
The final output that you sepcify is excatly as I want it!&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Tom</description>
      <pubDate>Wed, 17 Feb 2010 16:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58663#M16481</guid>
      <dc:creator>tomop</dc:creator>
      <dc:date>2010-02-17T16:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58664#M16482</link>
      <description>Hi:&lt;BR /&gt;
  So let's take a look at one possible (theoretical) example of "fake" data from 2 of the files...If the data looked like something like this for RR1 and RR2:&lt;BR /&gt;
[pre]&lt;BR /&gt;
RR1&lt;BR /&gt;
Date      PRED1 x1 x2 x3&lt;BR /&gt;
01/01/2010 111  1  2  3&lt;BR /&gt;
01/02/2010 222  4  5  6&lt;BR /&gt;
           &lt;BR /&gt;
                                               &lt;BR /&gt;
RR2&lt;BR /&gt;
Date      PRED2 y1 y2 x3&lt;BR /&gt;
01/01/2010 333  4  5  6&lt;BR /&gt;
01/02/2010 444  7  8  9&lt;BR /&gt;
01/03/2010 555  9  8  7&lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
What would you expect the results to look like:&lt;BR /&gt;
&lt;B&gt;Concatenated Results&lt;/B&gt;&lt;BR /&gt;
[pre]&lt;BR /&gt;
Date      PRED1  PRED2&lt;BR /&gt;
01/01/2010 111     .&lt;BR /&gt;
01/01/2010  .     333   &lt;BR /&gt;
01/02/2010 222     .&lt;BR /&gt;
01/02/2010  .     444  &lt;BR /&gt;
01/03/2010  .     555  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                      &lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Merged or Joined Results&lt;/B&gt;&lt;BR /&gt;
[pre]&lt;BR /&gt;
Date      PRED1 PRED2&lt;BR /&gt;
01/01/2010 111   333  &lt;BR /&gt;
01/02/2010 222   444&lt;BR /&gt;
01/03/2010  .    555  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
             &lt;BR /&gt;
The way the data looks and the desired result will determine the method you use to bring the files together, as described here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001081414.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001081414.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 18 Feb 2010 01:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/58664#M16482</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-02-18T01:13:26Z</dc:date>
    </item>
  </channel>
</rss>

