<?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: Nested Loop and splitting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455432#M115202</link>
    <description>&lt;P&gt;ods excel style=Seaside options(sheet_name="&amp;amp;&amp;amp;unit&lt;FONT color="#FF0000"&gt;&amp;amp;i&lt;/FONT&gt; Control Chart" SHEET_INTERVAL= 'PAGE' autofilter='1' FROZEN_ROWHEADERS='no' &lt;BR /&gt;embedded_titles='yes' embedded_footnotes='yes' embed_titles_once = 'on'&lt;BR /&gt;embedded_titles='on'&lt;BR /&gt;gridlines='off' START_AT='3,3');&lt;/P&gt;
&lt;P&gt;Title "&amp;amp;&amp;amp;unit&lt;FONT color="#FF0000"&gt;&amp;amp;i&lt;/FONT&gt; Control Chart";&lt;/P&gt;
&lt;P&gt;proc shewhart data=toch (where=(TEAM="&amp;amp;&amp;amp;unit&lt;FONT color="#FF0000"&gt;&amp;amp;i&lt;/FONT&gt;"));&lt;BR /&gt;xchart nruns * YrMajor/nolegend MARKERS ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to have "j" instead of "i" here.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Apr 2018 01:38:25 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-04-19T01:38:25Z</dc:date>
    <item>
      <title>Nested Loop and splitting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455421#M115196</link>
      <description>&lt;P&gt;Hi all;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I am attempting to run macro loops within each other-&lt;/P&gt;
&lt;P&gt;In this example I am using the sashelp.baseball dataset as I can't use company data but the concept and results are the same-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in this case-the first loop outputs data from the league (American,National) and outputs via proc report into separate excel documents. This part works fine-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's the nested loop that becomes the issue where for each league report-I am attempting to output a proc shewart graph for each team in the&amp;nbsp; league on separate tabs-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, while it produces separate excel workbooks for each league, it simply repeats the same team&amp;nbsp;&lt;SPAN&gt;shewart graph for each tab.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;(ie. for the National League it outputs Chicago 12 times)&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am sure I am missing something simple.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code follows below-&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Assistance much appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Lawrence&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=SASHELP.baseball out=BASEBALL;&lt;BR /&gt;by YrMajor;&lt;BR /&gt;run;&lt;BR /&gt;%macro ambulA (data=, var=);&lt;BR /&gt; proc sort data=&amp;amp;data(keep=&amp;amp;var) out=values nodupkey;&lt;BR /&gt; by &amp;amp;var;&lt;BR /&gt; run;&lt;BR /&gt; data _null_;&lt;BR /&gt; set values end=last;&lt;BR /&gt; call symputx('facid'||left(_n_),&amp;amp;var);&lt;BR /&gt; &lt;BR /&gt; if last then call symputx('count1',_n_, 'g');&lt;BR /&gt; run;&lt;BR /&gt;%put _local_;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA _NULL_ ;&lt;BR /&gt;select(&amp;amp;var);&lt;BR /&gt;%do i=1 %to &amp;amp;count1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options center;&lt;BR /&gt;ods listing close;&lt;/P&gt;
&lt;P&gt;title ' ';&lt;/P&gt;
&lt;P&gt;footnote1 j=l H=1 ' ';&lt;/P&gt;
&lt;P&gt;title1 H=4 "DATA Statistics";&lt;BR /&gt;title2 H=4 "FOR &amp;amp;&amp;amp;facid&amp;amp;i";&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ods excel file="c:\temp\&amp;amp;&amp;amp;facid&amp;amp;i...xlsx" style=Seaside options(sheet_name="league" SHEET_INTERVAL= 'PAGE' autofilter='1' FROZEN_ROWHEADERS='no' &lt;BR /&gt;GRIDLINES='ON' embedded_titles='yes' embedded_footnotes='yes');&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc report data=baseball (where=(League= "&amp;amp;&amp;amp;facid&amp;amp;i")) headline headskip nowd spanrows&lt;BR /&gt;style (column)={background=white just=center color=black font =("arial",7.5pt)}&lt;BR /&gt;style (header)={background=white just=center color=black font =("arial",8.0pt)};&lt;/P&gt;
&lt;P&gt;columns League YrMajor Team nRuns ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table toch as select distinct Team,YrMajor,sum(nruns) as nruns&lt;BR /&gt;from baseball &lt;BR /&gt;where League= "&amp;amp;&amp;amp;facid&amp;amp;i"&lt;BR /&gt;group by Team,YrMajor;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro ambulB (data=, varx=);&lt;BR /&gt; proc sort data=&amp;amp;data(keep=&amp;amp;varx) out=valuesx nodupkey;&lt;BR /&gt; by &amp;amp;varx;&lt;BR /&gt; run;&lt;BR /&gt; data _null_;&lt;BR /&gt; set valuesx end=last;&lt;BR /&gt; call symputx('unit'||left(_n_),&amp;amp;varx);&lt;BR /&gt; if last then call symputx('count3',_n_,'g');&lt;BR /&gt; run;&lt;BR /&gt;%put _local_;&lt;/P&gt;
&lt;P&gt;DATA _NULL_ ;&lt;BR /&gt;select(&amp;amp;varx);&lt;BR /&gt;%do J=1 %to &amp;amp;count3;&lt;/P&gt;
&lt;P&gt;symbol2 c=blue value=dot h=3.0 pct;&lt;/P&gt;
&lt;P&gt;ods excel style=Seaside options(sheet_name="&amp;amp;&amp;amp;unit&amp;amp;i Control Chart" SHEET_INTERVAL= 'PAGE' autofilter='1' FROZEN_ROWHEADERS='no' &lt;BR /&gt; embedded_titles='yes' embedded_footnotes='yes' embed_titles_once = 'on'&lt;BR /&gt; embedded_titles='on'&lt;BR /&gt; gridlines='off' START_AT='3,3');&lt;/P&gt;
&lt;P&gt;Title "&amp;amp;&amp;amp;unit&amp;amp;i Control Chart";&lt;/P&gt;
&lt;P&gt;proc shewhart data=toch (where=(TEAM="&amp;amp;&amp;amp;unit&amp;amp;i"));&lt;BR /&gt; xchart nruns * YrMajor/nolegend MARKERS ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%mend ambulB;&lt;BR /&gt;%ambulB (data=toch, varx=team);&lt;/P&gt;
&lt;P&gt;ODS _ALL_ Close;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%ambulA(data=Baseball, var=League);&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 23:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455421#M115196</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2018-04-18T23:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop and splitting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455424#M115197</link>
      <description>&lt;P&gt;Are you sure the code you posted can be executed without error?&lt;/P&gt;
&lt;P&gt;(It is highly recommended that you post your code with 'Insert sas code' commad so that it can be more readable.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't run you code but I think the reason might be the macro call in the inner loop is only pushed into a stack and won't be executed until the data step is completed.&lt;/P&gt;
&lt;P&gt;Try 'call exectute' or 'dosubl'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shen&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 00:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455424#M115197</guid>
      <dc:creator>ShenQicheng</dc:creator>
      <dc:date>2018-04-19T00:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop and splitting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455430#M115200</link>
      <description>&lt;P&gt;Your syntax is invalid. Why do you have these?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DATA _NULL_ ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select(&amp;amp;varx);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;remove these and try.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 01:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455430#M115200</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-19T01:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop and splitting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455432#M115202</link>
      <description>&lt;P&gt;ods excel style=Seaside options(sheet_name="&amp;amp;&amp;amp;unit&lt;FONT color="#FF0000"&gt;&amp;amp;i&lt;/FONT&gt; Control Chart" SHEET_INTERVAL= 'PAGE' autofilter='1' FROZEN_ROWHEADERS='no' &lt;BR /&gt;embedded_titles='yes' embedded_footnotes='yes' embed_titles_once = 'on'&lt;BR /&gt;embedded_titles='on'&lt;BR /&gt;gridlines='off' START_AT='3,3');&lt;/P&gt;
&lt;P&gt;Title "&amp;amp;&amp;amp;unit&lt;FONT color="#FF0000"&gt;&amp;amp;i&lt;/FONT&gt; Control Chart";&lt;/P&gt;
&lt;P&gt;proc shewhart data=toch (where=(TEAM="&amp;amp;&amp;amp;unit&lt;FONT color="#FF0000"&gt;&amp;amp;i&lt;/FONT&gt;"));&lt;BR /&gt;xchart nruns * YrMajor/nolegend MARKERS ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to have "j" instead of "i" here.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 01:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455432#M115202</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-19T01:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop and splitting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455651#M115303</link>
      <description>&lt;P&gt;Ah-thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lawrence&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 15:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-and-splitting/m-p/455651#M115303</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2018-04-19T15:55:31Z</dc:date>
    </item>
  </channel>
</rss>

