<?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 set up macro for proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903334#M356952</link>
    <description>&lt;P&gt;Hello folks, I have a large volume of tables to process and basically I have the main body of the code ready, but I don't know how to set up a macro to let the whole part of code run by each center. Below is the beginning of my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Macros;
%LET Regctr = WS;
%LET fy = 2022-2023;
%LET RCFULL = Full name of the center;

*Import excel file for data source;
proc import out=&amp;amp;Regctr. datafile= "&amp;amp;inpath\&amp;amp;Regctr..xlsx" 
	 dbms=xlsx replace;
	 sheet="_&amp;amp;Regctr";
     getnames=yes;
run;

*SEPARATE CONTRACTS;
DATA &amp;amp;Regctr.; SET &amp;amp;Regctr.;
	UCI_0=INPUT(UCI,12.);
RUN;

DATA &amp;amp;Regctr.; SET &amp;amp;Regctr.;
	WHERE UCI_0 NE . ; RUN;
RUN;&lt;BR /&gt;&lt;BR /&gt;Main&amp;nbsp;bulk&amp;nbsp;of&amp;nbsp;the&amp;nbsp;code&amp;nbsp;continue&amp;nbsp;to&amp;nbsp;the&amp;nbsp;very&amp;nbsp;end&amp;nbsp;...&amp;nbsp;and&amp;nbsp;then&amp;nbsp;at&amp;nbsp;the&amp;nbsp;proc&amp;nbsp;report&amp;nbsp;step&amp;nbsp;below:&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*---------------------------------SAS output, complete version, separate by tabs------------------------;
ODS EXCEL FILE='Tables.xlsx' 
 OPTIONS(SHEET_INTERVAL='none' SHEET_NAME='table1' EMBEDDED_TITLES='yes'
 TAB_COLOR='green' START_AT='2,4' FROZENHEADERS='yes');

OPTIONS MISSING='0';
ODS ESCAPECHAR='^';

title1 j=center bold font=calibri "my title";
title2 j=center bold font=calibri "some other title";
title3 j=right italic font=calibri "Fiscal Year &amp;amp;fy";
title4 j=right italic font=calibri "Page 1 of 1";
title5 j=left italic font=calibri "&amp;amp;RCFull";
title6 j=left bold font=calibri "All Ages";

PROC REPORT DATA=tbl1 NOWD HEADSKIP HEADLINE SPACING=1 
 	STYLE(report)={width=100%}
	STYLE(column)=[background=white fontstyle=roman fontsize=3 fontweight=medium  
				  fontfamily='calibri']
	STYLE(header)=[background=white fontstyle=roman fontsize=3 fontweight=bold 
				  fontfamily='calibri']
	STYLE(lines)=[background=white fontstyle=roman fontweight=medium  
				  fontfamily='calibri' color=black]
;
&lt;BR /&gt;...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, I have a total of 21 centers that I need to run the same code over again, and&amp;nbsp; below is what i am trying to resolve:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;how could I set up the macro so that it grabs the two-letter abbreviations (in the above example, WS needs to be changed to another two letter abbreviation such as AB, CB, EB, etc when WS part has finished running) and then also change the full name accordingly?&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;by the time the code runs towards the end, i also need the macro to save the tables using the two-letter abbreviation, for example, change the current part&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;ODS EXCEL FILE='Tables.xlsx' &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to something like&amp;nbsp;&lt;CODE class=" language-sas"&gt;ODS EXCEL FILE='WS.xlsx' and&amp;nbsp;go&amp;nbsp;on...&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel this might be something easy to accomplish but i can't figure out a proper way, any ideas? Thank you so much!&lt;/P&gt;</description>
    <pubDate>Wed, 15 Nov 2023 20:54:46 GMT</pubDate>
    <dc:creator>kevsma</dc:creator>
    <dc:date>2023-11-15T20:54:46Z</dc:date>
    <item>
      <title>set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903334#M356952</link>
      <description>&lt;P&gt;Hello folks, I have a large volume of tables to process and basically I have the main body of the code ready, but I don't know how to set up a macro to let the whole part of code run by each center. Below is the beginning of my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Macros;
%LET Regctr = WS;
%LET fy = 2022-2023;
%LET RCFULL = Full name of the center;

*Import excel file for data source;
proc import out=&amp;amp;Regctr. datafile= "&amp;amp;inpath\&amp;amp;Regctr..xlsx" 
	 dbms=xlsx replace;
	 sheet="_&amp;amp;Regctr";
     getnames=yes;
run;

*SEPARATE CONTRACTS;
DATA &amp;amp;Regctr.; SET &amp;amp;Regctr.;
	UCI_0=INPUT(UCI,12.);
RUN;

DATA &amp;amp;Regctr.; SET &amp;amp;Regctr.;
	WHERE UCI_0 NE . ; RUN;
RUN;&lt;BR /&gt;&lt;BR /&gt;Main&amp;nbsp;bulk&amp;nbsp;of&amp;nbsp;the&amp;nbsp;code&amp;nbsp;continue&amp;nbsp;to&amp;nbsp;the&amp;nbsp;very&amp;nbsp;end&amp;nbsp;...&amp;nbsp;and&amp;nbsp;then&amp;nbsp;at&amp;nbsp;the&amp;nbsp;proc&amp;nbsp;report&amp;nbsp;step&amp;nbsp;below:&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*---------------------------------SAS output, complete version, separate by tabs------------------------;
ODS EXCEL FILE='Tables.xlsx' 
 OPTIONS(SHEET_INTERVAL='none' SHEET_NAME='table1' EMBEDDED_TITLES='yes'
 TAB_COLOR='green' START_AT='2,4' FROZENHEADERS='yes');

OPTIONS MISSING='0';
ODS ESCAPECHAR='^';

title1 j=center bold font=calibri "my title";
title2 j=center bold font=calibri "some other title";
title3 j=right italic font=calibri "Fiscal Year &amp;amp;fy";
title4 j=right italic font=calibri "Page 1 of 1";
title5 j=left italic font=calibri "&amp;amp;RCFull";
title6 j=left bold font=calibri "All Ages";

PROC REPORT DATA=tbl1 NOWD HEADSKIP HEADLINE SPACING=1 
 	STYLE(report)={width=100%}
	STYLE(column)=[background=white fontstyle=roman fontsize=3 fontweight=medium  
				  fontfamily='calibri']
	STYLE(header)=[background=white fontstyle=roman fontsize=3 fontweight=bold 
				  fontfamily='calibri']
	STYLE(lines)=[background=white fontstyle=roman fontweight=medium  
				  fontfamily='calibri' color=black]
;
&lt;BR /&gt;...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, I have a total of 21 centers that I need to run the same code over again, and&amp;nbsp; below is what i am trying to resolve:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;how could I set up the macro so that it grabs the two-letter abbreviations (in the above example, WS needs to be changed to another two letter abbreviation such as AB, CB, EB, etc when WS part has finished running) and then also change the full name accordingly?&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;by the time the code runs towards the end, i also need the macro to save the tables using the two-letter abbreviation, for example, change the current part&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;ODS EXCEL FILE='Tables.xlsx' &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to something like&amp;nbsp;&lt;CODE class=" language-sas"&gt;ODS EXCEL FILE='WS.xlsx' and&amp;nbsp;go&amp;nbsp;on...&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel this might be something easy to accomplish but i can't figure out a proper way, any ideas? Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 20:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903334#M356952</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2023-11-15T20:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903379#M356964</link>
      <description>&lt;P&gt;If you can accept all output in a single Excel file, such as tables.xlsx, with TABs labelled by the two letter abbreviation, the you can do all of the reports with a single PROC REPORT and a BY statement in PROC REPORT, and the proper ODS EXCEL options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you absolutely have to have them all in separate Excel files, then please explain how the programmer will know the next two letter abbreviation after WS. Where is that information stored?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 22:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903379#M356964</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-15T22:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903384#M356965</link>
      <description>&lt;P&gt;Create a table with the 21 list of codes and names. &lt;BR /&gt;&lt;BR /&gt;Take the full code and wrap it in a macro &lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run_report (code = , name = , fy=);
code ....
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Test it with a few manual calls.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;
%run_report (code = WS, name = Station1, fy = 2022-2023);
%run_report(code= AB, name=Random, fy=2021-2022);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Get this working first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Tutorial on converting a working program to a macro&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&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;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&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;</description>
      <pubDate>Wed, 15 Nov 2023 22:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903384#M356965</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-11-15T22:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903392#M356968</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; I want each center's file to be a separate excel file, instead of having them all in one excel file. can I store the 2-letter abbreviation and their corresponding full name in excel file saved on local drive, say, saved it the same path as &amp;amp;inpath. I can also import it into a SAS proc format file like below:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
Value  $CENTER2     
                    "WC" = "NAME1"        
                    "BC" = "NAME2"        
                    "CB" = "NAME3"       
                    "GT" = "NAME4"     
                    ...&lt;BR /&gt;;     
run;      &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Would this work?&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 22:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903392#M356968</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2023-11-15T22:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903530#M357003</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;Thanks for the reply, I tried to plug in the example you showed here but SAS spits out errors, my beginning part looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run_report (Regctr = , RCFULL = );
&lt;BR /&gt;*main part of the code begins;
  *Import excel file first;
  proc import out=&amp;amp;Regctr. datafile= "&amp;amp;inpath\&amp;amp;Regctr..xlsx" 
	 dbms=xlsx replace;
	 sheet="_&amp;amp;Regctr";
     getnames=yes;
  run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the end looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...main code...&lt;BR /&gt;ODS EXCEL CLOSE;

%mend;


%run_report(Regctr = CV, rcfull = full name 1, fy = 2022-2023);
%run_report(Regctr = BV, rcfull = full name 2, fy = 2022-2023);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;anything i may be missing? thanks!!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 17:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903530#M357003</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2023-11-16T17:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903541#M357012</link>
      <description>&lt;P&gt;If you don't show the errors how do you expect us to address them?&lt;/P&gt;
&lt;P&gt;With macros that means setting OPTIONS MPRINT; before running the macro so the errors appear near the code that generates them.&lt;/P&gt;
&lt;P&gt;Then copy that generated code and the errors from the log and paste into a text box on the forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 19:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903541#M357012</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-16T19:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: set up macro for proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903566#M357021</link>
      <description>no worries, I got it worked out, turns out to be a space accidentally added to a format variable. thanks!</description>
      <pubDate>Thu, 16 Nov 2023 21:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-up-macro-for-proc-report/m-p/903566#M357021</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2023-11-16T21:25:10Z</dc:date>
    </item>
  </channel>
</rss>

