<?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: Dynamically setting start and end variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193073#M48462</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I thought macro variables could be 65534.&amp;nbsp; Guess I need to RTM.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Mar 2015 21:59:33 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2015-03-03T21:59:33Z</dc:date>
    <item>
      <title>Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193068#M48457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I have a dataset with 70 or so vehicle factors. My sas program is setup so that it takes each factors and creates a number of different graphs for analysis. I have the code working perfectly for one factor and I want to expand it to include all factors using a macro. I would rather not have to individually call each factor as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro1(factor1);&lt;/P&gt;&lt;P&gt;%macro1(factor2);&lt;/P&gt;&lt;P&gt;%macro1(factor3);&lt;/P&gt;&lt;P&gt;%macro1(factor4);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%macro1(factor70);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the data set the factors are listed under field "Factor". Is there a way of scanning this field, working out how many factors there are and then using a dynamic approach to achieving what I am trying to above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my head, this would work like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;scan column&lt;/P&gt;&lt;P&gt;there are x factors&lt;/P&gt;&lt;P&gt;do I from 1st to last factor&lt;/P&gt;&lt;P&gt;%macro(i)&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 17:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193068#M48457</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2015-03-03T17:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193069#M48458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Possibly something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro macro1(factor);&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc print data=sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; where sex eq "&amp;amp;factor.";&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro driver;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct factor&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :factors&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.class (rename=(sex=factor))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=1 %to &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %macro1(%scan(&amp;amp;factors.,&amp;amp;i.));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%driver&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 18:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193069#M48458</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-03-03T18:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193070#M48459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Call execute works well for calling a macro multiple times:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dates;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input date $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10nov97&lt;/P&gt;&lt;P&gt;11nov97&lt;/P&gt;&lt;P&gt;12nov97&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data reptdata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input date $ var1 var2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10nov97 25 10&lt;/P&gt;&lt;P&gt;10nov97 50 11&lt;/P&gt;&lt;P&gt;11nov97 23 10&lt;/P&gt;&lt;P&gt;11nov97 30 29&lt;/P&gt;&lt;P&gt;12nov97 33 44&lt;/P&gt;&lt;P&gt;12nov97 75 86&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro rept(dat,a,dsn);&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc chart data=&amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp; title "Chart for &amp;amp;dat";&lt;/P&gt;&lt;P&gt;&amp;nbsp; where(date="&amp;amp;dat");&lt;/P&gt;&lt;P&gt;&amp;nbsp; vbar &amp;amp;a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend rept;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set dates;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('%rept('||date||','||'var1,reptdata)');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 19:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193070#M48459</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-03-03T19:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193071#M48460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When the number of values is reasonable then using SQL to build a macro variable is a useful way to do this, but note there is a limitation of 32,767 characters to a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select distinct cats('%macro1(',&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;factor&lt;/STRONG&gt;&lt;/SPAN&gt;,')')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;mycode&lt;/STRONG&gt;&lt;/SPAN&gt; separated by ';'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;mytable&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;amp;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;mycode&lt;/STRONG&gt;&lt;/SPAN&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 21:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193071#M48460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-03-03T21:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193072#M48461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Writing lines of code to a file to be included later is another method for dynamic code generation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;filename &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;mycode&lt;/STRONG&gt;&lt;/SPAN&gt; temp ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; set &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;mytable&lt;/STRONG&gt;&lt;/SPAN&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; by &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;factor&lt;/STRONG&gt;&lt;/SPAN&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; file mycode;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; if first.&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;factor&lt;/STRONG&gt;&lt;/SPAN&gt; then put '%macro1(' &lt;STRONG style="color: #ff0000;"&gt;factor&lt;/STRONG&gt;= ');' ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%include &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;mycode&lt;/STRONG&gt;&lt;/SPAN&gt; / source2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 21:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193072#M48461</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-03-03T21:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193073#M48462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I thought macro variables could be 65534.&amp;nbsp; Guess I need to RTM.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 21:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193073#M48462</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-03-03T21:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically setting start and end variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193074#M48463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I stand corrected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2240&amp;nbsp; proc sql ;&lt;/P&gt;&lt;P&gt;2241&amp;nbsp;&amp;nbsp;&amp;nbsp; select x into :xx separated by ''&lt;/P&gt;&lt;P&gt;2242&amp;nbsp;&amp;nbsp;&amp;nbsp; from x&lt;/P&gt;&lt;P&gt;2243&amp;nbsp;&amp;nbsp;&amp;nbsp; where i&amp;lt;=1023&lt;/P&gt;&lt;P&gt;2244&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;ERROR: The length of the value of the macro variable XX (65540) exceeds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the maximum length (65534). The value has been truncated to 65534&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; characters.&lt;/P&gt;&lt;P&gt;2245&amp;nbsp;&amp;nbsp;&amp;nbsp; %put %length(&amp;amp;xx);&lt;/P&gt;&lt;P&gt;65534&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 22:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamically-setting-start-and-end-variable/m-p/193074#M48463</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-03-03T22:16:37Z</dc:date>
    </item>
  </channel>
</rss>

