<?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: Processing multiple months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723652#M224588</link>
    <description>I'll try call execute. Any documentation would be greatly appreciated.&lt;BR /&gt;</description>
    <pubDate>Thu, 04 Mar 2021 21:18:45 GMT</pubDate>
    <dc:creator>luvscandy27</dc:creator>
    <dc:date>2021-03-04T21:18:45Z</dc:date>
    <item>
      <title>Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723637#M224580</link>
      <description>&lt;P&gt;Hello all, I would like to know if there is any way for me to use the code below for several months. I have several rosters from January to December. The code below processes the roster for only January therefore I have to change the code multiple times to fit each month I am working with. I'm processing them separately since I need to have a rolling twelve months i.e. for February rosters the dates would be February 28 2017 to February 2018 and so on. The data below is only sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data date;&lt;BR /&gt;infile datalines delimiter = ',';&lt;BR /&gt;input ID $ DATE:mmddyy10. TYPE $11. PAIN HEART INPAT OUTPAT;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1, 05/03/2018, OUTPATIENT, ., 1, ., 1&lt;BR /&gt;1, 05/02/2018, OUTPATIENT, ., 1, ., 1&lt;BR /&gt;2, 01/26/2018, OUTPATIENT, 1, ., ., 1&lt;BR /&gt;2, 01/18/2018, OUTPATIENT, 1, ., ., 1&lt;BR /&gt;2, 01/10/2018, OUTPATIENT, 1, ., ., 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%macro split(cond, titlemonyr, ranstart, ranend);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;/*Split the conditions*/&lt;BR /&gt;proc sort data=date nodupkey out=&amp;amp;cond._&amp;amp;titlemonyr.;&lt;BR /&gt;by id date type;&lt;BR /&gt;where &amp;amp;cond.=1 and date ge "&amp;amp;ranstart."d and date le "&amp;amp;ranend."d ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Determine what cases meet the case definition (2 outpatient or one inpatient unless is head trauma. Note: &lt;BR /&gt;head trauma is counted once regardless of inpatient or outpatient. The look back period is one year.*/&lt;BR /&gt;data &amp;amp;cond._&amp;amp;titlemonyr._2;&lt;BR /&gt;set &amp;amp;cond._&amp;amp;titlemonyr.;&lt;BR /&gt;retain count;&lt;BR /&gt;by id date type;&lt;BR /&gt;if first.id then count= 1;&lt;BR /&gt;else count = count + 1;/*adding the total appointments*/&lt;BR /&gt;%if &amp;amp;cond. ne HT %then %do; &lt;BR /&gt;if last.id and count = 1 and INPAT = . then delete;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend split;&lt;BR /&gt;%split (PAIN, JAN2018, 31jan2017, 31jan2018);&lt;BR /&gt;%split (HEART, JAN2018, 31jan2017, 31jan2018);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 20:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723637#M224580</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2021-03-04T20:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723641#M224583</link>
      <description>Look into CALL EXECUTE() and how you can use it to call your macro multiple times. &lt;BR /&gt;&lt;BR /&gt;Or you can redesign your entire process to handle multiple groups at once. Looking at your code, it looks like counts over overlapping periods, which makes me consider a Multilabel format and PROC TABULATE. &lt;BR /&gt;&lt;BR /&gt;The first method is faster, programming wise and will definitely work with your current code. &lt;BR /&gt;The second method is longer, programming wise, but likely faster run time and you'll probably learn a lot. &lt;BR /&gt;There are probably other methods but these are the ones I'd recommend given what I see here. Which approach would you like to attempt? I can provide some more relevant references based on your answer. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723641#M224583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-04T21:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723652#M224588</link>
      <description>I'll try call execute. Any documentation would be greatly appreciated.&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723652#M224588</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2021-03-04T21:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723666#M224599</link>
      <description>&lt;P&gt;Below should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date;
	infile datalines delimiter = ',';
	input ID $ DATE:mmddyy10. TYPE $11. PAIN HEART INPAT OUTPAT;
	format date mmddyy10.;
	datalines;
1, 05/03/2018, OUTPATIENT, ., 1, ., 1
1, 05/02/2018, OUTPATIENT, ., 1, ., 1
2, 01/26/2018, OUTPATIENT, 1, ., ., 1
2, 01/18/2018, OUTPATIENT, 1, ., ., 1
2, 01/10/2018, OUTPATIENT, 1, ., ., 1
;
run;


%macro split(cond);

%macro _;
%mend _;

proc sql;
	select distinct put(date,monyy5.)
		into :date1 - :date&amp;amp;sysmaxlong
			from date;
	%let cnt = &amp;amp;sqlobs;
quit;

/*Split the conditions*/
%do i = 1 %to &amp;amp;cnt;
	%let d_start = %sysfunc(intnx(month,"01||&amp;amp;&amp;amp;date&amp;amp;i"d,0,b),date9.);
	%let d_end = %sysfunc(intnx(year,"01||&amp;amp;&amp;amp;date&amp;amp;i"d,0,e),date9.);
	%put &amp;amp;=d_start &amp;amp;=d_end;

	proc sort data=date nodupkey out=&amp;amp;cond._&amp;amp;&amp;amp;date&amp;amp;i.;
		by id date type;
		where &amp;amp;cond.=1 and date &amp;gt;= "&amp;amp;d_start"d and date &amp;lt;= "&amp;amp;d_end"D;
	run;

	/*Determine what cases meet the case definition (2 outpatient or one inpatient unless is head trauma. Note:
	head trauma is counted once regardless of inpatient or outpatient. The look back period is one year.*/
	data &amp;amp;cond._&amp;amp;&amp;amp;date&amp;amp;i.._2;
		set &amp;amp;cond._&amp;amp;&amp;amp;date&amp;amp;i.;
		retain count;
		by id date type;

		if first.id then
			count= 1;
		else count = count + 1;/*adding the total appointments*/

		%if &amp;amp;cond. ne HT %then
			%do;
				if last.id and count = 1 and INPAT = . then
					delete;
			%end;
	run;

%end;
%mend split;

%split (PAIN);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723666#M224599</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-03-04T21:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723672#M224603</link>
      <description>&lt;P&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank" rel="noopener"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to add data to a regular data set and report it&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/353374a5d8ea4f0c89ce5d80a47f4a4c" target="_blank"&gt;https://gist.github.com/statgeek/353374a5d8ea4f0c89ce5d80a47f4a4c&lt;/A&gt;&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;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255656"&gt;@luvscandy27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'll try call execute. Any documentation would be greatly appreciated.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723672#M224603</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-04T21:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723682#M224607</link>
      <description>&lt;P&gt;This is great however, I am very new at macro processing . I hate to ask this but could you provide me with an explanation of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is happening in the code? Also, the sample data I put in the post only processes January data. With the code you provide can I process all months at one time or do I need to separate the months?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723682#M224607</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2021-03-04T21:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723686#M224609</link>
      <description>Thanks to Art Carpenter from whom I learned this technique many years back. The SQL procedure moves the dates into macro variables which are then essentially used to subset the dataset based on the date conditions. It should be able to process all months; keep an eye out in the log and turn on the MPRINT and MLOGIC system options to view the code generated by the macro facility.</description>
      <pubDate>Thu, 04 Mar 2021 21:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723686#M224609</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-03-04T21:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723693#M224614</link>
      <description>Thank you!&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 22:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723693#M224614</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2021-03-04T22:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723702#M224621</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I'm processing them separately since I need to have a rolling twelve months i.e. for February rosters the dates would be February 28 2017 to February 2018 and so on. The data below is only sample data.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What analysis will be done once the data is split? Rolling what? Average?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all you want is rolling averages, no macros or CALL EXECUTE are needed, you can use PROC EXPAND to get all the rolling statistics (including average, standard deviation and many many others) over all of your 12 month time periods, in one call to the PROC. Let's not decide that you have to have macros or CALL EXECUTE just yet.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 22:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-months/m-p/723702#M224621</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-04T22:31:46Z</dc:date>
    </item>
  </channel>
</rss>

