<?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: SAS Macro to automate the code in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574505#M12715</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89720"&gt;@sameer112217&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Wow sir brilliant. Wish I can be as half good as you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not brilliant. Just "non-complicated" thinking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first thing I noticed: you have a loop over years, so that made up my outer loop.&lt;/P&gt;
&lt;P&gt;The second thing I noticed: the final month number is a multiple of 12 and corresponds to the number of years to calculate. Tadaaa: the inner loop!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Strive to see the obvious patterns. Only when you find none, you &lt;EM&gt;may&lt;/EM&gt; have to resort to complicated techniques. But even then, start with the simplest approach and see if you can beat it into shape with some extensions.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2019 09:32:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-07-18T09:32:55Z</dc:date>
    <item>
      <title>SAS Macro to automate the code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574498#M12710</link>
      <description>&lt;P&gt;I want to automate the below code for creating this table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dummy;&lt;BR /&gt;input UW_Year$4. month_diff_modified;&lt;BR /&gt;datalines;&lt;BR /&gt;2015 3&lt;BR /&gt;2015 6&lt;BR /&gt;2015 9&lt;BR /&gt;2015 12&lt;BR /&gt;2015 15&lt;BR /&gt;2015 18&lt;BR /&gt;2015 21&lt;BR /&gt;2015 24&lt;BR /&gt;2015 27&lt;BR /&gt;2015 30&lt;BR /&gt;2015 33&lt;BR /&gt;2015 36&lt;BR /&gt;2015 39&lt;BR /&gt;2015 42&lt;BR /&gt;2015 45&lt;BR /&gt;2015 48&lt;/P&gt;&lt;P&gt;2015 51&lt;/P&gt;&lt;P&gt;2015 54&lt;/P&gt;&lt;P&gt;2015 57&lt;/P&gt;&lt;P&gt;2015 60&lt;BR /&gt;2016 3&lt;BR /&gt;2016 6&lt;BR /&gt;2016 9&lt;BR /&gt;2016 12&lt;BR /&gt;2016 15&lt;BR /&gt;2016 18&lt;BR /&gt;2016 21&lt;BR /&gt;2016 24&lt;BR /&gt;2016 27&lt;BR /&gt;2016 30&lt;BR /&gt;2016 33&lt;BR /&gt;2016 36&lt;/P&gt;&lt;P&gt;2016 39&lt;/P&gt;&lt;P&gt;2016 42&lt;/P&gt;&lt;P&gt;2016 45&lt;BR /&gt;2016 48&lt;BR /&gt;2017 6&lt;BR /&gt;2017 9&lt;BR /&gt;2017 12&lt;BR /&gt;2017 15&lt;BR /&gt;2017 18&lt;BR /&gt;2017 21&lt;BR /&gt;2017 24&lt;/P&gt;&lt;P&gt;2017 27&lt;/P&gt;&lt;P&gt;2017 30&lt;/P&gt;&lt;P&gt;2017 33&lt;/P&gt;&lt;P&gt;2017 36&lt;BR /&gt;2018 03&lt;BR /&gt;2018 06&lt;BR /&gt;2018 09&lt;BR /&gt;2018 12&lt;/P&gt;&lt;P&gt;2018 15&lt;/P&gt;&lt;P&gt;2018 18&lt;/P&gt;&lt;P&gt;2018 21&lt;/P&gt;&lt;P&gt;2018 24&lt;/P&gt;&lt;P&gt;2019 03&lt;/P&gt;&lt;P&gt;2019 06&lt;/P&gt;&lt;P&gt;2019 09&lt;/P&gt;&lt;P&gt;2019 12&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The general rule is it should start with April 2015 and the end year should be next year and in my case it is March 2020 since this is the 7th month. IF this is less than 4 months it has to be 2019. The flow should be like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2015&amp;nbsp; 03&lt;/P&gt;&lt;P&gt;2015 06&lt;/P&gt;&lt;P&gt;.........&lt;/P&gt;&lt;P&gt;........&lt;/P&gt;&lt;P&gt;2015 60&amp;nbsp; (since 2015 apri to 2020 mar is 60 months) it needs to be increased by 3&lt;/P&gt;&lt;P&gt;2016 03&lt;/P&gt;&lt;P&gt;2016 06&lt;/P&gt;&lt;P&gt;.........&lt;/P&gt;&lt;P&gt;............&lt;/P&gt;&lt;P&gt;2016 48&amp;nbsp; ( since distance between 2016 apr to 2020 march is 48 months)&lt;/P&gt;&lt;P&gt;Same for 2017, 2018 and 2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a macro variable to store previous year. Then I calculated the period between 2015 and 2020 using intck and then i used the do loop and increase by 3 to create the table.. somehow i am stuck in automating it . The area where I am stuck is for 2016 I need to calculate it from 2016 to 2020..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know of any simpler way&amp;nbsp; to achieve this task. I need this in the sas dataset table&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574498#M12710</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2019-07-18T09:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to automate the code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574499#M12711</link>
      <description>&lt;P&gt;I used just a basic macro to create the table structure however I was stuck in the part where do loop should have calculations for 2016 onward incremental&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options symbolgen mlogic mprint;&lt;BR /&gt;%macro datecalc;&lt;BR /&gt;%global cyear1;&lt;BR /&gt;data _null_;&lt;BR /&gt;call symputx('cmonth',month(today()));&lt;BR /&gt;call symputx('cmonth_name',put(month(today()),monname.));&lt;BR /&gt;call symputx('cyear',year(today()));&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;cmonth. &amp;amp;cyear.;&lt;/P&gt;&lt;P&gt;%if &amp;amp;cmonth &amp;gt;=4 %then %do;&lt;BR /&gt;%let cyear1= %sysevalf(&amp;amp;cyear +1);&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let cyear1=%bquote(&amp;amp;cyear.);&lt;BR /&gt;%end;&lt;BR /&gt;%put &amp;amp;cyear1.;&lt;/P&gt;&lt;P&gt;data table;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i = 2015 %to&amp;nbsp;&amp;amp;cyear1;&lt;/P&gt;&lt;P&gt;%let diff= %sysfunc(intnx('month','01APR&amp;amp;i.,'31MAR&amp;amp;cyear1.'d));&lt;/P&gt;&lt;P&gt;%do j=&amp;nbsp; 3 %to &amp;amp;diff&amp;amp;i by 3;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;BR /&gt;%datecalc;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574499#M12711</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2019-07-18T09:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to automate the code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574501#M12712</link>
      <description>&lt;P&gt;Just two nested do loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startyear=2015;
%let endyear=2019;

data want;
do year = &amp;amp;startyear. to &amp;amp;endyear.;
  do month_diff_modified = 3 to ((&amp;amp;endyear. + 1) - year) * 12 by 3;
    output;
  end;
end;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;        month_diff_
year      modified

2015          3    
2015          6    
2015          9    
2015         12    
2015         15    
2015         18    
2015         21    
2015         24    
2015         27    
2015         30    
2015         33    
2015         36    
2015         39    
2015         42    
2015         45    
2015         48    
2015         51    
2015         54    
2015         57    
2015         60    
2016          3    
2016          6    
2016          9    
2016         12    
2016         15    
2016         18    
2016         21    
2016         24    
2016         27    
2016         30    
2016         33    
2016         36    
2016         39    
2016         42    
2016         45    
2016         48    
2017          3    
2017          6    
2017          9    
2017         12    
2017         15    
2017         18    
2017         21    
2017         24    
2017         27    
2017         30    
2017         33    
2017         36    
2018          3    
2018          6    
2018          9    
2018         12    
2018         15    
2018         18    
2018         21    
2018         24    
2019          3    
2019          6    
2019          9    
2019         12    
&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574501#M12712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-18T09:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to automate the code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574502#M12713</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89720"&gt;@sameer112217&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used just a basic macro to create the table structure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options symbolgen mlogic mprint;&lt;BR /&gt;%macro datecalc;&lt;BR /&gt;%global cyear1;&lt;BR /&gt;data _null_;&lt;BR /&gt;call symputx('cmonth',month(today()));&lt;BR /&gt;call symputx('cmonth_name',put(month(today()),monname.));&lt;BR /&gt;call symputx('pmonth',month(intnx('month',today(),-1)));&lt;BR /&gt;call symputx('cyear',year(today()));&lt;BR /&gt;call symputx('pyear',year(intnx('month',today(),-1)));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;cmonth. &amp;amp;cyear.;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;cmonth &amp;gt;=4 %then %do;&lt;BR /&gt;%let cyear1= %sysevalf(&amp;amp;cyear +1);&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let cyear1=%bquote(&amp;amp;cyear.);&lt;BR /&gt;%end;&lt;BR /&gt;%put &amp;amp;cyear1.;&lt;BR /&gt;%let diff= %sysfunc(intnx('month','01APR2015'd,'31MAR&amp;amp;cyear1.'d));&lt;/P&gt;
&lt;P&gt;/*%do i=2015 %to &amp;amp;cyear1;*/&lt;BR /&gt;/*%do f=3 %to */&lt;BR /&gt;%mend;&lt;BR /&gt;%datecalc;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Forget your macro obsession. Learn to use Base SAS first.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574502#M12713</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-18T09:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to automate the code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574504#M12714</link>
      <description>&lt;P&gt;Wow sir brilliant. Wish I can be as half good as you.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574504#M12714</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2019-07-18T09:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to automate the code</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574505#M12715</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89720"&gt;@sameer112217&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Wow sir brilliant. Wish I can be as half good as you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not brilliant. Just "non-complicated" thinking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first thing I noticed: you have a loop over years, so that made up my outer loop.&lt;/P&gt;
&lt;P&gt;The second thing I noticed: the final month number is a multiple of 12 and corresponds to the number of years to calculate. Tadaaa: the inner loop!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Strive to see the obvious patterns. Only when you find none, you &lt;EM&gt;may&lt;/EM&gt; have to resort to complicated techniques. But even then, start with the simplest approach and see if you can beat it into shape with some extensions.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Macro-to-automate-the-code/m-p/574505#M12715</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-18T09:32:55Z</dc:date>
    </item>
  </channel>
</rss>

