<?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: Loop not processing second step in it in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938819#M368711</link>
    <description>Gotcha. I was overlooking the local component in doing this. Makes sense. Thanks for the insight.</description>
    <pubDate>Fri, 09 Aug 2024 17:59:43 GMT</pubDate>
    <dc:creator>sas_user_1001</dc:creator>
    <dc:date>2024-08-09T17:59:43Z</dc:date>
    <item>
      <title>Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938809#M368706</link>
      <description>&lt;P&gt;I have a SAS dataset called "holidays" that is structured as shown below that spans 1985-2023. I have dummy variables for the Friday and the weekend, and most importantly holidays.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_user_1001_0-1723222521440.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99162iC871EB0F495114DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_user_1001_0-1723222521440.png" alt="sas_user_1001_0-1723222521440.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I am trying to write a loop which works through a list of all months and days of the week to determine what percentage of a day of the week, for a given month, falls on a holiday. For instance, what percentage of Monday's in January have been a federal holiday between 1985 and 2023? What percentage of Tuesday's in January, etc... Below is my code thus far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;%let m_list = 1 2 3 4 5 6 7 8 9 10 11 12;&lt;/DIV&gt;
&lt;DIV&gt;%let d_list = 1 2 3 4 5 6 7;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro holidays(list1,list2);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%local month day next_month next_day;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%do month = 1 %to %sysfunc(countw(&amp;amp;m_list));&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; %let next_month = %scan(&amp;amp;m_list,&amp;amp;month);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %do day = 1 %to %sysfunc(countw(&amp;amp;d_list));&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let next_day = %scan(&amp;amp;d_list,&amp;amp;day);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; proc freq data = holidays;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; where Month = &amp;amp;next_month and dow = &amp;amp;next_day;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; table HolDum / out = prob_&amp;amp;next_month._&amp;amp;next_day;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; data _null_;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; set prob_&amp;amp;next_month._&amp;amp;next_day;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if HolDum = 0 then call symput("M&amp;amp;next_month._&amp;amp;next_day._0",PERCENT/100);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; else if HolDum = 1 then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; call symput("M&amp;amp;next_month._&amp;amp;next_day._1",PERCENT/100);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end; run;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;%end;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%mend holidays;&lt;/DIV&gt;
&lt;DIV&gt;%holidays(&amp;amp;m_list,&amp;amp;d_list)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%put &amp;amp;M1_1_0 &amp;amp;M1_1_1 &amp;amp;M1_2_0 &amp;amp;M1_2_1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Where I am stuck is the data _null_ step--the loop does not seem to be assigning percentages for the holiday dummy variable to the variable name (as verified when I run the %put statement). Can someone help me troubleshoot this. I'm relatively new to SAS so this might be a SAS issue I'm not seeing, or perhaps just a logic issue I'm missing. Thanks.&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Aug 2024 17:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938809#M368706</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-08-09T17:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938810#M368707</link>
      <description>&lt;P&gt;Why are you trying to print the value of LOCAL macro variables after the macro has finished running?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 17:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938810#M368707</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-09T17:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938811#M368708</link>
      <description>If I'm understanding correctly, you are asking why I have %put at the end for the binary variables? I am simply wanting to see that the code assigned the percentages as I intended; it's just a check. Those percentages get called up and used later on in the code.</description>
      <pubDate>Fri, 09 Aug 2024 17:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938811#M368708</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-08-09T17:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938813#M368709</link>
      <description>&lt;P&gt;Before you started down this macro path did you have code that worked for some period that did not involve any macro variables or coding?&lt;/P&gt;
&lt;P&gt;If not the basic approach is to do such. Then see if a macro is even needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your HOLDUM variable supposed to be the indicator that the day is a holiday?&lt;/P&gt;
&lt;P&gt;If so you may want to consider either of these codes:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=holidays;
  class month dow;
  var holdum;
  table month,
        dow*holdum*mean*f=percent8.2;
run;

proc tabulate data=holidays;
  class month dow holdum;
  table month,
        dow*holdum*pctn&amp;lt;month&amp;gt;
       /misstext=' ';
run;
&lt;/PRE&gt;
&lt;P&gt;Which uses the power of the procedure to do the grouping and counting.&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;Proc freq data=holidays;
  tables month*dow*holdum/outpercent;
  ods output crosstabfreqs=myoutput;
run;&lt;/PRE&gt;
&lt;P&gt;though the output data set Myoutput would need a bit of massaging to get just the holidays. Look at the variable ROWPERCENT where HOLDUM=1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea what your dummy variables mean or what role they play in this exercise. So you may discuss them.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 17:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938813#M368709</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-09T17:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938814#M368710</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463968"&gt;@sas_user_1001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;If I'm understanding correctly, you are asking why I have %put at the end for the binary variables? I am simply wanting to see that the code assigned the percentages as I intended; it's just a check. Those percentages get called up and used later on in the code.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Placing that much calculation result into macro variables is usually a poor idea.&lt;/P&gt;
&lt;P&gt;How exactly are those macro values used later?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the point is that the macro variables involved with your %put do no exist after the macro ends as they are local in scope with code as written.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 17:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938814#M368710</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-09T17:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938819#M368711</link>
      <description>Gotcha. I was overlooking the local component in doing this. Makes sense. Thanks for the insight.</description>
      <pubDate>Fri, 09 Aug 2024 17:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938819#M368711</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-08-09T17:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938820#M368712</link>
      <description>Yes, if HolDum = 1 then it is a federal holiday; 0 otherwise. These %ages I'm trying to utilize are used when I do a data simulation later on. I want the frequency these holidays show up in historical data to show up at the same rate in the simulation.</description>
      <pubDate>Fri, 09 Aug 2024 18:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938820#M368712</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-08-09T18:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938821#M368713</link>
      <description>&lt;P&gt;I wanted to circle back to this point. I was able to specify the variable names using symputx with 'G' to make these global variables. The code now works due to this insight.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 18:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938821#M368713</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-08-09T18:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938822#M368714</link>
      <description>&lt;P&gt;Assuming that HOLDUM is coded as 1/0 with 1 meaning HOLIDAY you can get your results using PROC SUMMARY.&amp;nbsp; The MEAN of a 1/0 variable is the percent of times the value was 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=holidays nway;
  class month dow ;
  var holdum;
  output out=percent_holiday mean=percent_holiday;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you can also skip the macro variables since you could just use the dataset to drive your simulation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's try it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data holidays;
  do date='01JAN1985'd to '31DEC2023'd ;
    month=month(date);
    dow=weekday(date);
    holdum=0&amp;lt;holidaycount(date);
    output;
  end;
  format date yymmdd10.;
run;

proc summary data=holidays nway;
  class month dow ;
  var holdum;
  output out=percent_holiday mean=percent_holiday;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If we check how often Thursday in November is a holiday we get just over 26% of the time.&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.PERCENT_HOLIDAY" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;11&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;167&lt;/TD&gt;
&lt;TD class="r data"&gt;0.26347&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Aug 2024 18:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938822#M368714</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-09T18:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Loop not processing second step in it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938824#M368715</link>
      <description>&lt;P&gt;If your process is modeling dates then you should be able to get one of the HOLIDAY functions with that to tell if the date is a holidy.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 18:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-not-processing-second-step-in-it/m-p/938824#M368715</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-09T18:55:56Z</dc:date>
    </item>
  </channel>
</rss>

