<?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 SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26506#M4732</link>
    <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I am back again. I have a file with 365 days of data and 24 hours of each day going horizontally. for example&lt;BR /&gt;
&lt;BR /&gt;
Date             Hour1    Hour2     Hour3  ........Hour24&lt;BR /&gt;
01/01/10      2.5          5.2          6.4             5.8&lt;BR /&gt;
01/02/10       8.5        6.2           7.4           5.9&lt;BR /&gt;
01/03/10     0            7.4           5.7            2.5&lt;BR /&gt;
&lt;BR /&gt;
What I need to do is move hours 13-24 to a new row with the same date. For example&lt;BR /&gt;
&lt;BR /&gt;
Date             Hour1    Hour2     Hour3  ........Hour12   &lt;BR /&gt;
01/01/10      2.5          5.2          6.4             5.8&lt;BR /&gt;
01/01/10      8.5        6.2           7.4           5.9   &amp;lt;----- hours 13-24&lt;BR /&gt;
01/02/10    0            7.4           5.7            2.5&lt;BR /&gt;
01/02/10&lt;BR /&gt;
&lt;BR /&gt;
I'm not even sure where to begin here. Since the column headers are the hours, telling SAS to move the columns isn't really an option? Thanks for any suggestions.</description>
    <pubDate>Tue, 02 Nov 2010 13:33:37 GMT</pubDate>
    <dc:creator>Aar684</dc:creator>
    <dc:date>2010-11-02T13:33:37Z</dc:date>
    <item>
      <title>SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26506#M4732</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I am back again. I have a file with 365 days of data and 24 hours of each day going horizontally. for example&lt;BR /&gt;
&lt;BR /&gt;
Date             Hour1    Hour2     Hour3  ........Hour24&lt;BR /&gt;
01/01/10      2.5          5.2          6.4             5.8&lt;BR /&gt;
01/02/10       8.5        6.2           7.4           5.9&lt;BR /&gt;
01/03/10     0            7.4           5.7            2.5&lt;BR /&gt;
&lt;BR /&gt;
What I need to do is move hours 13-24 to a new row with the same date. For example&lt;BR /&gt;
&lt;BR /&gt;
Date             Hour1    Hour2     Hour3  ........Hour12   &lt;BR /&gt;
01/01/10      2.5          5.2          6.4             5.8&lt;BR /&gt;
01/01/10      8.5        6.2           7.4           5.9   &amp;lt;----- hours 13-24&lt;BR /&gt;
01/02/10    0            7.4           5.7            2.5&lt;BR /&gt;
01/02/10&lt;BR /&gt;
&lt;BR /&gt;
I'm not even sure where to begin here. Since the column headers are the hours, telling SAS to move the columns isn't really an option? Thanks for any suggestions.</description>
      <pubDate>Tue, 02 Nov 2010 13:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26506#M4732</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-11-02T13:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26507#M4733</link>
      <description>A DATA step with two OUTPUT statements, one for each unique file.  And your DATA statement would have the two files listed with different KEEP= lists (the Hour_ variable values split up), as required.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 02 Nov 2010 14:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26507#M4733</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-02T14:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26508#M4734</link>
      <description>Scott, &lt;BR /&gt;
&lt;BR /&gt;
I need to end up with only one file. When you say use a data step with an output for each unique file, do you mean output hours 1-12 into a data file then output 13-24 into a data file and combine them by date? Or am I interpretting this wrong.</description>
      <pubDate>Tue, 02 Nov 2010 14:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26508#M4734</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-11-02T14:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26509#M4735</link>
      <description>You could try something like the following untested code,&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
set have;&lt;BR /&gt;
array Hour(24) Hour1-Hour24;&lt;BR /&gt;
output;&lt;BR /&gt;
do i=1 to 12;&lt;BR /&gt;
hour(i)=hour(i+12);&lt;BR /&gt;
end;&lt;BR /&gt;
output;&lt;BR /&gt;
drop hour13-hour24;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Good luck!</description>
      <pubDate>Tue, 02 Nov 2010 14:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26509#M4735</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-11-02T14:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26510#M4736</link>
      <description>Rick, &lt;BR /&gt;
&lt;BR /&gt;
That code works perfectly, however I would like to better understand it. I understand the concept of loops as I have a basic background in C++. I just don't see how the code takes hours 13-24 and moves them below 1-12. The code works, but can you explain it quickly so that I may understand better for next time?</description>
      <pubDate>Tue, 02 Nov 2010 14:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26510#M4736</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-11-02T14:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26511#M4737</link>
      <description>Actually I think I understand. In the second part of the code you output 12 + i. I see I think.</description>
      <pubDate>Tue, 02 Nov 2010 14:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26511#M4737</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-11-02T14:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26512#M4738</link>
      <description>The do loop works like a for loop would in other languages.  By default SAS increments the value by 1 so you could have also writen it as:&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to 12 by 1;&lt;BR /&gt;
...&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
So after each iteration the value of i increases by 1.&lt;BR /&gt;
&lt;BR /&gt;
This loop happens for each row in the original data set.  The first output statement writes the entire observation to the new dataset.  The loop the shifts each hour value over 12 places.  Then the second output statement writes the modified observation to the new dataset.  If you dont include the drop statement you will see that the values of hour13-hour24 haven't actually changed.&lt;BR /&gt;
&lt;BR /&gt;
To learn more about loops in SAS (or SAS in general) go to lexjansen.com which has many papers from SAS conferences.</description>
      <pubDate>Tue, 02 Nov 2010 15:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL/m-p/26512#M4738</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-11-02T15:10:02Z</dc:date>
    </item>
  </channel>
</rss>

