<?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: Making a code dynamic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544192#M150486</link>
    <description>&lt;P&gt;The previous target (j) need to be calculated I guess&lt;/P&gt;</description>
    <pubDate>Tue, 19 Mar 2019 09:30:44 GMT</pubDate>
    <dc:creator>Kiteulf</dc:creator>
    <dc:date>2019-03-19T09:30:44Z</dc:date>
    <item>
      <title>Making a code dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544191#M150485</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Target3=(sum(1,M_201810)*sum(1,Target2))-1;
Target4=(sum(1,M_201809)*sum(1,Target3))-1;
Target5=(sum(1,M_201808)*sum(1,Target4))-1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have a code which calculates the Target1,Target2,Target3 etc...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this not dynamic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have come so far on the dynamic code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro create(howmany);
   %do i=1  %to &amp;amp;howmany;

%let j =&amp;amp;i-1 ;

DATA _NULL_;
%let today=%sysfunc(today());
 %let somnow=%sysfunc(intnx(month,&amp;amp;today,-&amp;amp;i,b), yymmn6.);
%let somnow1=%sysfunc(intnx(month,&amp;amp;today,-&amp;amp;i,b), date9.);  
 run;

 %put &amp;amp;somnow;

DATA PD32T_&amp;amp;i;
set PD32TRANS;
format Date_&amp;amp;i yymmn6.;
Date_&amp;amp;i = "&amp;amp;somnow1"d;
Target&amp;amp;i=(sum(1,M_&amp;amp;somnow)*sum(1,Target&amp;amp;j))-1;
if Target&amp;amp;i = 0 then delete;
run;
Proc sql;&lt;BR /&gt;create table Target_data_&amp;amp;i as&lt;BR /&gt;select t0.objectregnbr &lt;BR /&gt;,t1.Date&amp;amp;i as DATE&lt;BR /&gt;,t1.Target&amp;amp;i &lt;BR /&gt;from PD32TRANS as t0&lt;BR /&gt;left join PD32T_&amp;amp;i as t1&lt;BR /&gt;on t0.objectregnbr = t1.objectregnbr&lt;BR /&gt;;&lt;BR /&gt;Quit;
 
 %end;
%mend create;

%create(12)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need some help to complete the code. Maybe there are far better ways to do this without making 12 different files and aggregating them up... But principally looking for a way that calculates Target backwards in time&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 09:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544191#M150485</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2019-03-19T09:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Making a code dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544192#M150486</link>
      <description>&lt;P&gt;The previous target (j) need to be calculated I guess&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 09:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544192#M150486</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2019-03-19T09:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Making a code dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544200#M150488</link>
      <description>&lt;P&gt;This change is mandatory:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let j = %eval(&amp;amp;i - 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other changes are recommended, such as removing this line entirely:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA _NULL_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET statements are never part of a DATA step.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 10:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544200#M150488</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-19T10:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Making a code dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544212#M150492</link>
      <description>&lt;P&gt;First thing to do: create a version without any macro-statement. If you already have that code, post it, so we can help. It seems as if the target-varialbes can be calculated using a normal do-loop and arrays. But to suggest something usefull i need to see data you have and what you expect as result.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 12:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-a-code-dynamic/m-p/544212#M150492</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-19T12:02:53Z</dc:date>
    </item>
  </channel>
</rss>

