<?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: Weekday and hour number interaction variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387394#M277314</link>
    <description>&lt;P&gt;This is the first time I have ever posted here. &amp;nbsp;I need these for proc reg later. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Aug 2017 16:00:04 GMT</pubDate>
    <dc:creator>MetricsKevin</dc:creator>
    <dc:date>2017-08-11T16:00:04Z</dc:date>
    <item>
      <title>Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387377#M277311</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have scoured the internet to no avail. I'm hoping someone would be able to help. &amp;nbsp;I need to interact dummy variables for the day of the week and the hour of the day. &amp;nbsp;I really don't want to hard code 168 variables. &amp;nbsp;I have to do this pretty regularly&amp;nbsp;so I feel like learning a loop based method to would really help. &amp;nbsp;I already have the weekday and hour dummies that are 1 if true. &amp;nbsp;I would like to create 168 interactions that have names like day1_he1 ... day7_he24 that = 1 when the specified day and specified hour are both 1. &amp;nbsp;I am using SAS eg with base 9.02.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a date variable and a variable called HE which is the hour of the day. &amp;nbsp;Here is what I have tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data work.sample_data;&lt;/P&gt;&lt;P&gt;set work.sample_data;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;weekday = weekday(date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array ar_day{*} day1-day7;&lt;BR /&gt;do j = 1 to 7;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ar_day(j) = (weekday=j);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array ar_he{*} he1-he24;&lt;BR /&gt;do k = 1 to 24;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ar_he(k) =(he=k);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do l = 1 to 7;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; do m = 1 to 24;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; day&amp;amp;l_he&amp;amp;m = day&amp;amp;l*he&amp;amp;m;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ther error I receive is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference L_HE not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference M not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference M not resolved.&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 15:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387377#M277311</guid>
      <dc:creator>MetricsKevin</dc:creator>
      <dc:date>2017-08-11T15:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387382#M277312</link>
      <description>&lt;P&gt;In your final do loop you're putting an ampersand in front of L_HE, M and L which makes SAS interpret them as macro variables when in fact they're data step variables which is why you're getting the errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can post a sample of your input data and output data in the form of data step so we can easily re-create it we can more easily give you a solution.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 15:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387382#M277312</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-08-11T15:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387387#M277313</link>
      <description>&lt;P&gt;1. Why did you create a new ID? I'm assuming you're the same person who posted about &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Weekday-dummy-Variables/m-p/387125#M92795" target="_self"&gt;weekday variables yesterday&lt;/A&gt;?&lt;/P&gt;
&lt;P&gt;2. What procedure are you using afterwards? As indicated in the original question, depending on the procedures you can sometimes use the CLASS statement to avoid all of this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/158513"&gt;@MetricsKevin&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have scoured the internet to no avail. I'm hoping someone would be able to help. &amp;nbsp;I need to interact dummy variables for the day of the week and the hour of the day. &amp;nbsp;I really don't want to hard code 168 variables. &amp;nbsp;I have to do this pretty regularly&amp;nbsp;so I feel like learning a loop based method to would really help. &amp;nbsp;I already have the weekday and hour dummies that are 1 if true. &amp;nbsp;I would like to create 168 interactions that have names like day1_he1 ... day7_he24 that = 1 when the specified day and specified hour are both 1. &amp;nbsp;I am using SAS eg with base 9.02.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a date variable and a variable called HE which is the hour of the day. &amp;nbsp;Here is what I have tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data work.sample_data;&lt;/P&gt;
&lt;P&gt;set work.sample_data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;weekday = weekday(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array ar_day{*} day1-day7;&lt;BR /&gt;do j = 1 to 7;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ar_day(j) = (weekday=j);&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array ar_he{*} he1-he24;&lt;BR /&gt;do k = 1 to 24;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ar_he(k) =(he=k);&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do l = 1 to 7;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; do m = 1 to 24;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; day&amp;amp;l_he&amp;amp;m = day&amp;amp;l*he&amp;amp;m;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ther error I receive is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference L_HE not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference M not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference M not resolved.&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is appreciated.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 15:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387387#M277313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-11T15:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387394#M277314</link>
      <description>&lt;P&gt;This is the first time I have ever posted here. &amp;nbsp;I need these for proc reg later. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 16:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387394#M277314</guid>
      <dc:creator>MetricsKevin</dc:creator>
      <dc:date>2017-08-11T16:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387395#M277315</link>
      <description>&lt;P&gt;Im having a hard time exporting my data in sas form. &amp;nbsp;I was able to get it into excel and have posted below. &amp;nbsp;Its just dates in date9. and he is a number 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 16:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387395#M277315</guid>
      <dc:creator>MetricsKevin</dc:creator>
      <dc:date>2017-08-11T16:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387400#M277316</link>
      <description>&lt;P&gt;Try PROC GLM with a CLASS statement instead. Create two variables, one that represents the weekday, using 1 to 7 and one that represents the hour, 0 to 23 or 1 to 24.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;class weekday hour;

model dependent = weekday*hour ;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Aug 2017 16:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387400#M277316</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-11T16:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387406#M277317</link>
      <description>&lt;P&gt;My bosses would really prefer that I stick to proc reg. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 16:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387406#M277317</guid>
      <dc:creator>MetricsKevin</dc:creator>
      <dc:date>2017-08-11T16:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387462#M277318</link>
      <description>&lt;P&gt;This is the code causing the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;do l = 1 to 7;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; do m = 1 to 24;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; day&amp;amp;l_he&amp;amp;m = day&amp;amp;l*he&amp;amp;m;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It you don't want to code all the assignment statements, macro language can do it for you. &amp;nbsp;This would be the replacement code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%macro loop;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%local i m;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%do i = 1 %to 7;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %do m = 1 %to 24;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; day&amp;amp;i._he&amp;amp;m = day&amp;amp;i.*he&amp;amp;m;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mend loop;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%loop&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 18:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387462#M277318</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-11T18:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387477#M277319</link>
      <description>&lt;P&gt;This was the trick. &amp;nbsp;I didn't know you could put macros in data steps, mind = blown.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 19:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387477#M277319</guid>
      <dc:creator>MetricsKevin</dc:creator>
      <dc:date>2017-08-11T19:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387500#M277320</link>
      <description>&lt;P&gt;Remember, the macro language statements are not part of the DATA step. &amp;nbsp;Instead, they are generating 144 SAS language assignment statements, which become part of the DATA step. &amp;nbsp;If you run the program using this statement beforehand, you can observe that in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 21:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387500#M277320</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-11T21:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Weekday and hour number interaction variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387565#M277321</link>
      <description>&lt;P&gt;You don't need to write hard code to get this design matrix . Look this:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Aug 2017 10:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Weekday-and-hour-number-interaction-variables/m-p/387565#M277321</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-12T10:01:46Z</dc:date>
    </item>
  </channel>
</rss>

