<?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: roll out key value per hour in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772741#M39686</link>
    <description>&lt;P&gt;For the BY to work properly, the dataset must be sorted in ascending sequence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My DATA HAVE step is there to create data for testing and illustrating. To prepend a dummy observation to your existing dataset (so that the TRANSPOSE works as intended), do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;
set test_forum; /* get the column attributes */
test_number = 0; /* why do you store somemthing that will never be used in calculations as a number? */
hours = 23;
start_hour = 0;
key_value = .;
output;
stop;
run;

data test_forum;
set
  dummy
  test_forum
;
run;

proc sort data=test_forum;
by test_number;
run;

data long;
set test_forum;
do hr = start_hour to start_hour + hours - 1;
  output;
end;
run;

proc transpose
  data=long
  out=want (drop=_name_ where=(test_number ne 0))
;
by test_number hours start_hour;
var key_value;
id hr;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the "data step with datalines" is the ONLY(!) method to properly present source data here on the communities, as it lets everybody recreate a dataset with a simple copy/paste and submit, without having to code that on our own and make guesses along the way.&lt;/P&gt;
&lt;P&gt;If you want working and tested code, properly presented data is a MUST.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Oct 2021 14:08:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-10-07T14:08:38Z</dc:date>
    <item>
      <title>roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772689#M39679</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible in EG to create a formula in the red marked columns? (attachment in excel)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So that the "key value" is filled at the hour of the column "start hour" and that it is expanded with the number of hours of the column "amount of hours"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;see also the attachment in excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you so much for the comments&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 11:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772689#M39679</guid>
      <dc:creator>HansSteenhuis</dc:creator>
      <dc:date>2021-10-07T11:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772698#M39680</link>
      <description>&lt;P&gt;PROC REPORT does this from a long dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input test_number $ hours start_hour key_value;
datalines;
21085484 5 13 .8
25874521 3 15 .75
;

data long;
set have;
do hr = start_hour to start_hour + hours - 1;
  output;
end;
run;

proc report data=long;
column test_number hours start_hour key_value,hr;
define test_number / group;
define hours / group;
define start_hour / group;
define key_value / sum;
define hr / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to have all 24 columns even if no values are present, use the PRELOADFMT option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
fmtname = "myhr";
type = "N";
do start = 0 to 23;
  label = put(start,z2.);
  output;
end;
run;

proc format cntlin=cntlin;
run;

proc report data=long;
column test_number hours start_hour key_value,hr;
define test_number / group;
define hours / group;
define start_hour / group;
define key_value / sum;
define hr / "" across format=myhr. preloadfmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772698#M39680</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-07T12:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772699#M39681</link>
      <description>&lt;P&gt;Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software or organization policy. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772699#M39681</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-07T12:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772705#M39682</link>
      <description>&lt;P&gt;thank you very much&lt;/P&gt;&lt;P&gt;is it possible for this to be a table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Knipsel.JPG" style="width: 792px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64453i8E8B3AE1E9E93121/image-size/large?v=v2&amp;amp;px=999" role="button" title="Knipsel.JPG" alt="Knipsel.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772705#M39682</guid>
      <dc:creator>HansSteenhuis</dc:creator>
      <dc:date>2021-10-07T12:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772712#M39683</link>
      <description>&lt;P&gt;You can use ODS Excel to present this report to people who don't use SAS; for working with data, the long dataset layout is always more useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still want a wide dataset, PROC TRANSPOSE does this, but you need a dummy observation to force all hours from 0 to 23:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=" ";
input test_number $ hours start_hour key_value;
datalines;
 23 0 .
21085484 5 13 .8
25874521 3 15 .75
;

data long;
set have;
do hr = start_hour to start_hour + hours - 1;
  output;
end;
run;

proc transpose
  data=long
  out=want (drop=_name_ where=(test_number ne " "))
;
by test_number hours start_hour;
var key_value;
id hr;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772712#M39683</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-07T12:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772715#M39684</link>
      <description>thank you very much</description>
      <pubDate>Thu, 07 Oct 2021 13:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772715#M39684</guid>
      <dc:creator>HansSteenhuis</dc:creator>
      <dc:date>2021-10-07T13:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772732#M39685</link>
      <description>&lt;P&gt;I do not get it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use this table:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Knipsel.JPG" style="width: 513px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64460i45054CAA2EF3A072/image-size/large?v=v2&amp;amp;px=999" role="button" title="Knipsel.JPG" alt="Knipsel.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then i use this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
infile datalines dsd dlm=" ";
input test_number $ hours start_hour key_value;
datalines;
 23 0 .
21085484 5 13 .8
25874521 3 15 .75
;

data long;
set _TEST_FORUM;
do hr = start_hour to start_hour + hours - 1;
  output;
end;
run;

proc transpose
  data=long
  out=want (drop=_name_ where=(test_number ne " "))
;
by test_number hours start_hour;
var key_value;
id hr;
run; &lt;/LI-CODE&gt;&lt;P&gt;But now I only get errors&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I must be doing something wrong&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772732#M39685</guid>
      <dc:creator>HansSteenhuis</dc:creator>
      <dc:date>2021-10-07T13:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772741#M39686</link>
      <description>&lt;P&gt;For the BY to work properly, the dataset must be sorted in ascending sequence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My DATA HAVE step is there to create data for testing and illustrating. To prepend a dummy observation to your existing dataset (so that the TRANSPOSE works as intended), do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;
set test_forum; /* get the column attributes */
test_number = 0; /* why do you store somemthing that will never be used in calculations as a number? */
hours = 23;
start_hour = 0;
key_value = .;
output;
stop;
run;

data test_forum;
set
  dummy
  test_forum
;
run;

proc sort data=test_forum;
by test_number;
run;

data long;
set test_forum;
do hr = start_hour to start_hour + hours - 1;
  output;
end;
run;

proc transpose
  data=long
  out=want (drop=_name_ where=(test_number ne 0))
;
by test_number hours start_hour;
var key_value;
id hr;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the "data step with datalines" is the ONLY(!) method to properly present source data here on the communities, as it lets everybody recreate a dataset with a simple copy/paste and submit, without having to code that on our own and make guesses along the way.&lt;/P&gt;
&lt;P&gt;If you want working and tested code, properly presented data is a MUST.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772741#M39686</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-07T14:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772940#M39696</link>
      <description>&lt;P&gt;Thank you very much, great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I have a start time of 21 and it runs for 8 hours. Then the code continues to count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Knipsel.JPG" style="width: 770px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64500i3819666A734A26C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Knipsel.JPG" alt="Knipsel.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Knipsel.JPG" style="width: 747px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64501i1CFF8E8DC0E52113/image-size/large?v=v2&amp;amp;px=999" role="button" title="Knipsel.JPG" alt="Knipsel.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can that also be solved?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A test can never last longer than 24 hours.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 07:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772940#M39696</guid>
      <dc:creator>HansSteenhuis</dc:creator>
      <dc:date>2021-10-08T07:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: roll out key value per hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772973#M39697</link>
      <description>&lt;P&gt;When you have time series spanning over midnight, you should consider adding a day indicator to the hour, eitherby using datetimes or a combined day-hour string. Otherwise the software will always put the hours after midnight to the left of the time series start.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 09:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/roll-out-key-value-per-hour/m-p/772973#M39697</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-08T09:31:45Z</dc:date>
    </item>
  </channel>
</rss>

