<?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: How to re-write the below function into a macro. I need to run the below format for 7 months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-re-write-the-below-function-into-a-macro-I-need-to-run/m-p/377681#M276758</link>
    <description>&lt;P&gt;Well, lets back up here for a minute. &amp;nbsp;First, it is quite hard to refactor anything without seeing a) some test data - in the form of a datastep, see this post if you need help:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and b) required output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A brief glance at your code provided shows a fair few areas for change, for instance just the first three steps could be:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table STEP_3 as 
  select  A.*,
          B.*
  from    (select * from MASTER where DATE='200101') A
  left join (select * from TIME_TABLE where DATE='200102') B
  on       A.DATE=B.TIME;
quit;&lt;/PRE&gt;
&lt;P&gt;I assume date is a character string? &amp;nbsp;If not then you need to put a date value in there - i.e. a numeric or date literal. &amp;nbsp;this is where seeing actual data helps. &amp;nbsp;Also, use of select * shows that you haven't thought about the data coming in (and can cause problems further on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thirdly, never start a problem by saying I need to use &amp;lt;xyz&amp;gt; technology, now how can I squeeze my problem into that as your sure to end up with a mess. &amp;nbsp;Just from what you post there, it seems you have the "excel" way of working going on, i.e. data in column headings going across the page which isn't the best way to work. &amp;nbsp;Put your data in the dataset, and name variables consistently and simple so that your code can access them without vast amounts of code needed to access the information. &amp;nbsp;Also put date into the dataset as a proper date variable, this way you will be, by easy use of maths or date functions, be able to pull out any selection of data for processing, i.e. you can do 7 month windows on the data and then process using those groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;So for me if I started with:&lt;/P&gt;
&lt;P&gt;date_201401 date_201402...&lt;/P&gt;
&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;567&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First step would be to remodel the data for programming activities:&lt;/P&gt;
&lt;P&gt;DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;JAN2014 &amp;nbsp; 123&lt;/P&gt;
&lt;P&gt;FEB2014 &amp;nbsp; 567&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thne know for my programming that there will always be two variables DATE and RESULT, and I can process dates using simple maths and date functions e.g.&lt;/P&gt;
&lt;P&gt;DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RESULT &amp;nbsp; WINDOW&lt;/P&gt;
&lt;P&gt;JAN2014 &amp;nbsp; 123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First 7 Months&lt;/P&gt;
&lt;P&gt;FEB2014 &amp;nbsp; 567 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First 7 Months&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;I can then group results, sum them etc. without loops and extra code, and if the output needs to look as it was, then a simple proc transpose call can achieve this, hence output as required, process data as required for programming - best of both worlds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jul 2017 10:04:28 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-07-20T10:04:28Z</dc:date>
    <item>
      <title>How to re-write the below function into a macro. I need to run the below format for 7 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-re-write-the-below-function-into-a-macro-I-need-to-run/m-p/377679#M276757</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table step_1 as select *&lt;BR /&gt;from master&amp;nbsp;&lt;BR /&gt;where date = '200101';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table step_2 as select *&lt;BR /&gt;from time_table&lt;BR /&gt;where date = 200102;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table step_3 as select a.*, b.*&lt;BR /&gt;from step_1 as a&lt;BR /&gt;left join step_2 as b&lt;BR /&gt;on a.date = b.time;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data step_5;&lt;BR /&gt;set step_4_1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array Month (6) &amp;nbsp;date_200101&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_200102&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_200103&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_200104&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_201510&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_201510&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_201510&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;do i = 1 to 7;&lt;BR /&gt;if Month{i} in ('90','120','150','180') then do;&lt;BR /&gt;bad = 1;&lt;BR /&gt;mnth = i;&lt;BR /&gt;i = 7;&lt;BR /&gt;end;&lt;BR /&gt;else bad = 0;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if month{7} in ('90','120','150','180') then do;&lt;BR /&gt;Bad_1 = 1;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;&lt;BR /&gt;else bad_1 = 0 ;&lt;BR /&gt;count_1 = 1;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 09:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-re-write-the-below-function-into-a-macro-I-need-to-run/m-p/377679#M276757</guid>
      <dc:creator>dugan123</dc:creator>
      <dc:date>2017-07-20T09:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to re-write the below function into a macro. I need to run the below format for 7 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-re-write-the-below-function-into-a-macro-I-need-to-run/m-p/377681#M276758</link>
      <description>&lt;P&gt;Well, lets back up here for a minute. &amp;nbsp;First, it is quite hard to refactor anything without seeing a) some test data - in the form of a datastep, see this post if you need help:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and b) required output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A brief glance at your code provided shows a fair few areas for change, for instance just the first three steps could be:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table STEP_3 as 
  select  A.*,
          B.*
  from    (select * from MASTER where DATE='200101') A
  left join (select * from TIME_TABLE where DATE='200102') B
  on       A.DATE=B.TIME;
quit;&lt;/PRE&gt;
&lt;P&gt;I assume date is a character string? &amp;nbsp;If not then you need to put a date value in there - i.e. a numeric or date literal. &amp;nbsp;this is where seeing actual data helps. &amp;nbsp;Also, use of select * shows that you haven't thought about the data coming in (and can cause problems further on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thirdly, never start a problem by saying I need to use &amp;lt;xyz&amp;gt; technology, now how can I squeeze my problem into that as your sure to end up with a mess. &amp;nbsp;Just from what you post there, it seems you have the "excel" way of working going on, i.e. data in column headings going across the page which isn't the best way to work. &amp;nbsp;Put your data in the dataset, and name variables consistently and simple so that your code can access them without vast amounts of code needed to access the information. &amp;nbsp;Also put date into the dataset as a proper date variable, this way you will be, by easy use of maths or date functions, be able to pull out any selection of data for processing, i.e. you can do 7 month windows on the data and then process using those groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;So for me if I started with:&lt;/P&gt;
&lt;P&gt;date_201401 date_201402...&lt;/P&gt;
&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;567&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First step would be to remodel the data for programming activities:&lt;/P&gt;
&lt;P&gt;DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;JAN2014 &amp;nbsp; 123&lt;/P&gt;
&lt;P&gt;FEB2014 &amp;nbsp; 567&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thne know for my programming that there will always be two variables DATE and RESULT, and I can process dates using simple maths and date functions e.g.&lt;/P&gt;
&lt;P&gt;DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RESULT &amp;nbsp; WINDOW&lt;/P&gt;
&lt;P&gt;JAN2014 &amp;nbsp; 123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First 7 Months&lt;/P&gt;
&lt;P&gt;FEB2014 &amp;nbsp; 567 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First 7 Months&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;I can then group results, sum them etc. without loops and extra code, and if the output needs to look as it was, then a simple proc transpose call can achieve this, hence output as required, process data as required for programming - best of both worlds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 10:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-re-write-the-below-function-into-a-macro-I-need-to-run/m-p/377681#M276758</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-20T10:04:28Z</dc:date>
    </item>
  </channel>
</rss>

