<?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 do I Run a Macro in do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852511#M336984</link>
    <description>&lt;P&gt;Thank you very much Tom!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed from ODS Excel to ODS PDF , and also moved ODS close to the end of the code. It works fantastic!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jan 2023 15:08:39 GMT</pubDate>
    <dc:creator>JohanK</dc:creator>
    <dc:date>2023-01-06T15:08:39Z</dc:date>
    <item>
      <title>How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/851961#M336758</link>
      <description>&lt;P&gt;Hello, I am not a very senior programmer and I try to run a SAS code, using a macro within a Do While Loop. Here are bits of my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT CEIL(MAX(VISNUM)) INTO :MAXVISNUM&amp;nbsp;&lt;BR /&gt;FROM LAB6;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let CNUM=1;&amp;nbsp;&lt;BR /&gt;%let VNUM=1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro LAB7;&lt;BR /&gt;DATA LAB7;&lt;BR /&gt;Length VISIT $18;&lt;BR /&gt;SET COHORT&amp;amp;CNUM.;&lt;BR /&gt;IF VISNUM NE &amp;amp;VNUM. THEN DELETE;&lt;BR /&gt;DROP LBORRESU LBORRES UNL ;&lt;BR /&gt;RUN;&lt;BR /&gt;%mend LAB7;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data MYDATA ;&lt;BR /&gt;VINUM=1;&lt;BR /&gt;do until (VINUM=&amp;amp;MAXVISNUM.);&lt;BR /&gt;%LAB7;&lt;BR /&gt;VINUM=VINUM+1;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it gives me these messages in the log:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;340 do until (VINUM=&amp;amp;MAXVISNUM.);&lt;BR /&gt;341 %LAB7;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.MYDATA may be incomplete. When this step was stopped&lt;BR /&gt;there were 0 observations and 1 variables.&lt;BR /&gt;WARNING: Data set WORK.MYDATA was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "LAB7".&lt;BR /&gt;1 DATA LAB7; Length VISIT $18; SET COHORT&amp;amp;CNUM.; IF VISNUM&lt;BR /&gt;-&lt;BR /&gt;---&lt;BR /&gt;117&lt;BR /&gt;161&lt;BR /&gt;1 ! NE &amp;amp;VNUM. THEN DELETE; END; DROP LBORRESU LBORRES UNL ; RUN;&lt;/P&gt;&lt;P&gt;ERROR 117-185: There was 1 unclosed DO block.&lt;/P&gt;&lt;P&gt;ERROR 161-185: No matching DO/SELECT statement.&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.LAB7 may be incomplete. When this step was stopped&lt;BR /&gt;there were 0 observations and 6 variables.&lt;BR /&gt;WARNING: Data set WORK.LAB7 was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;342 *%TRANSP;&lt;BR /&gt;343 *%WIDE;&lt;BR /&gt;344 VINUM+1;&lt;BR /&gt;-----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;345 end;&lt;BR /&gt;---&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;346 proc print;&lt;BR /&gt;347 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me out? I do not know what I am doing wrong&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 14:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/851961#M336758</guid>
      <dc:creator>JohanK</dc:creator>
      <dc:date>2023-01-03T14:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/851970#M336760</link>
      <description>&lt;P&gt;Macros produce code and that code replaces the macro call. The resulting code must be legal valid working SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you run your&amp;nbsp;program that has&amp;nbsp;&lt;SPAN&gt;%LAB7, the code that actually runs is this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT CEIL(MAX(VISNUM)) INTO :MAXVISNUM 
FROM LAB6;
QUIT;
%let CNUM=1; 
%let VNUM=1; 

data MYDATA ;
    VINUM=1;
    do until (VINUM=&amp;amp;MAXVISNUM.);
        /* Your %LAB7 is replaced by the contents of the macro */
        DATA LAB7;
            Length VISIT $18;
            SET COHORT&amp;amp;CNUM.;
            IF VISNUM NE &amp;amp;VNUM. THEN DELETE;
            DROP LBORRESU LBORRES UNL ;
        RUN; /* End of %LAB7 */ ;
      VINUM=VINUM+1;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;So you now have a DATA step inside a loop inside a DATA step. Is this legal SAS code? No, you can't have DATA steps inside of DATA steps.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When you try to write macros, very good advice is first to create working legal valid SAS code that does what you want for two cases, hard-coded, without macro variable and without macros. Therefore, we request that you follow this advice, produce this working SAS code without macros and without macro variables for two cases, hard-coded, and show that to us, which will then most likely be easy to turn into a macro, and we can help you at that point.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 15:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/851970#M336760</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-03T15:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/851987#M336770</link>
      <description>&lt;P&gt;I do not understand what you are trying to LOOP over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You definitely cannot execute a data step inside the middle of another data step.&amp;nbsp; So you logic cannot work (with or without using a macro to generate some of the code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain what you are trying to do.&amp;nbsp; (not HOW, but WHAT).&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 15:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/851987#M336770</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-03T15:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852004#M336781</link>
      <description>&lt;P&gt;Please post usable example data for dataset COHORT1 (because that is what you start with) in a &lt;STRONG&gt;DATA STEP WITH DATALINES (&lt;FONT color="#FF0000"&gt;nothing else!!!&lt;/FONT&gt;)&lt;/STRONG&gt; and show what you want to get out of it.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 17:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852004#M336781</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-03T17:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852005#M336782</link>
      <description>&lt;P&gt;Thank you so much Tom. Let me explain what I want to achieve...&lt;/P&gt;&lt;P&gt;I produce graphs with GPLOT at the end of the code from Labdata and in total there are over 25 variations of combinations of 2 variables which are needed as input: VISNUM and USUBJID. In order to avoid hardcoding and rerunning the program 25 times I want to use macros, also to prevent errors with hardcoding and a very long code. What I posted is one loop with one macro but in fact I need 2 loops ; a big one with a loop for VISNUM (within this loop 3 macros instead of 1) AND within that loop a smaller one with USUBJID. At the end I want to get 25 graphs..&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written code which works with hardcoding, just simple code. Now I would like to convert that code to code inclusive macros. Sorry if I cannot share more info since this is sensitive and confidential&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 17:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852005#M336782</guid>
      <dc:creator>JohanK</dc:creator>
      <dc:date>2023-01-03T17:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852006#M336783</link>
      <description>&lt;P&gt;Thank you so much Paige. Let me explain what I want to achieve...&lt;/P&gt;&lt;P&gt;I produce graphs with GPLOT at the end of the code from Labdata and in total there are over 25 variations of combinations of 2 variables which are needed as input: VISNUM and USUBJID. In order to avoid hardcoding and rerunning the program 25 times I want to use macros, also to prevent errors with hardcoding and a very long code. What I posted is one loop with one macro but in fact I need 2 loops ; a big one with a loop for VISNUM (within this loop 3 macros instead of 1) AND within that loop a smaller one with USUBJID. At the end I want to get 25 graphs..&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written code which works with hardcoding, just simple code. Now I would like to convert that code to code inclusive macros. Sorry that I cannot share more info ..&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 17:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852006#M336783</guid>
      <dc:creator>JohanK</dc:creator>
      <dc:date>2023-01-03T17:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852007#M336784</link>
      <description>&lt;P&gt;So you appear to have two values you want to pass.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want all values of VISIT combined with all values of SUBJECT?&amp;nbsp; Or do you just want the combinations that exist in your dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you just want the combinations that appear in your dataset then create a macro that takes two parameters and then call it once for each combination in your dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's assume the macro is named GPLOT and the parameters are named VISIT and SUBJECT.&amp;nbsp; So it might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro gplot(visit,subject);
proc gplot data=xxx;
  where visnum = "&amp;amp;visit" and usubjid = "&amp;amp;subject";
....
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you have a dataset named HAVE which as all of the combinations of VISNUM and USUBJECT you want to use to call that macro then just use it to generate the macro calls.&amp;nbsp; One way is to use the CALL EXECUTE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have;
  call execute(cats('%nrstr(%gplot)(',visnum,',',usubjid,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 17:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852007#M336784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-03T17:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852008#M336785</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I have written code which works with hardcoding, just simple code. Now I would like to convert that code to code inclusive macros. Sorry that I cannot share more info ..&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SHOW US the code.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 17:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852008#M336785</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-03T17:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852021#M336787</link>
      <description>&lt;P&gt;Hi - there's a few things going on here that I'll mention:&lt;/P&gt;
&lt;P&gt;1) you can't just place a macro call in a data step as you did because as SAS is scanning the data step, it's sending each line to the compiler - except for the macro trigger (%lab) in your program, which will be sent to the macro processor immediately and executed there.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Never place a semi-colon on a macro call - we only use semi-colons on SAS statements and a macro call is technically NOT a SAS statement.&lt;/P&gt;
&lt;P&gt;So I've tried to build a simple replica of your code as follows, which will work for you.&amp;nbsp; &amp;nbsp;While you can place the whole thing into a macro definition and a %do statement, this will work here:&lt;/P&gt;
&lt;P&gt;%macro lab7;&lt;BR /&gt;%put hello lab7, nice to meet you!;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%lab7&lt;BR /&gt;%let maxvisnum = 10;&lt;/P&gt;
&lt;P&gt;data mydata;&lt;BR /&gt;do until (vinum=&amp;amp;maxvisnum);&lt;BR /&gt;vinum+1;&lt;BR /&gt;call execute(%nrstr("%lab7"));&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Which yields a nice log:&lt;/P&gt;
&lt;P&gt;ata mydata;&lt;BR /&gt;33 do until (vinum=&amp;amp;maxvisnum);&lt;BR /&gt;34 vinum+1;&lt;BR /&gt;35 call execute(%nrstr("%lab7"));&lt;BR /&gt;36 end;&lt;BR /&gt;37 run;&lt;/P&gt;
&lt;P&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;hello lab7, nice to meet you!&lt;BR /&gt;NOTE: The data set WORK.MYDATA has 1 observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A bit of explanation as well:&amp;nbsp; &amp;nbsp;CALL EXECUTE permits you to send any code to the Input Stack when as needed.&amp;nbsp; The %nrstr function delays the execution of the %lab7 macro call, instead just stacking up the call 10 times in the Input Stack.&amp;nbsp; &amp;nbsp;It's a bit advanced, but this gets the job done for you.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 20:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852021#M336787</guid>
      <dc:creator>donricardo</dc:creator>
      <dc:date>2023-01-03T20:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852251#M336905</link>
      <description>&lt;P&gt;Thanks so much Tom!!! It works fine... I am so happy to have learned more from your help.&lt;BR /&gt;Could I ask you a second small question?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next small 'issue' I am facing is that ODS Excel only stores the last graphs. So the last record from the macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code for the macro , PROC GPLOT and ODS Excel. Probably I am not using some options correctly?&amp;nbsp; By the way, the dataset which I created is COH1 (all Subjects within Cohort 1)&lt;/P&gt;&lt;P&gt;What I would like is to have all graphs of all subjects on the same TAB.&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro gplot(subj);&lt;BR /&gt;&lt;BR /&gt;goptions reset=all cback=white border htext=8pt htitle=12pt;&lt;BR /&gt;&lt;BR /&gt;footnote;&lt;BR /&gt;&lt;BR /&gt;axis1 order=(1 to 26 by 1)&lt;BR /&gt;value=(font='Arial/bold' height=8pt)&lt;BR /&gt;offset=(4,4)&lt;BR /&gt;width=2&lt;BR /&gt;label=none&lt;BR /&gt;major=none&lt;BR /&gt;minor=none;&lt;BR /&gt;&lt;BR /&gt;axis2 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL. by 2)&lt;BR /&gt;label=(angle=90 'x UNL')&lt;BR /&gt;value=(tick=5 ' ' tick=10 ' ')&lt;BR /&gt;offset=(2,2);&lt;BR /&gt;axis3 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL. by 2)&lt;BR /&gt;label=(angle=90 'x UNL')&lt;BR /&gt;value=(tick=5 ' ' tick=10 ' ')&lt;BR /&gt;offset=(2,2);&lt;BR /&gt;&lt;BR /&gt;symbol1 interpol=join width=1 color=vligb value=dot height=.8;&lt;BR /&gt;symbol2 interpol=join width=1 color=salmon value=dot height=.8;&lt;BR /&gt;symbol3 interpol=join width=1 color=vibg value=dot height=.8;&lt;BR /&gt;symbol4 interpol=join width=1 color=red value=dot height=.8;&lt;BR /&gt;symbol5 interpol=join width=1 color=purple value=dot height=.8;&lt;BR /&gt;symbol6 interpol=join width=1 color=blue value=dot height=.8;&lt;BR /&gt;symbol7 interpol=join width=1 color=yellow value=dot height=.8;&lt;BR /&gt;symbol8 interpol=join width=1 color=green value=dot height=.8;&lt;BR /&gt;&lt;BR /&gt;symbol9 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol10 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol11 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol12 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol13 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol14 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol15 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol16 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;title;&lt;/P&gt;&lt;P&gt;ODS EXCEL FILE = "C:\Users\jkwaaitaal\OneDrive - Molecular Partners AG\Documents\MP0317\MP0317_LAB LIVER_GRAPHICS_%sysfunc(date(),DATE9.).xlsx"&lt;BR /&gt;options(embedded_titles='on' sheet_interval='page' sheet_name="COHORT 1-LAB A");&lt;BR /&gt;title1 "MP0317_ASAT ALAT LDH ALP BILIRUBIN LIPASE_COHORT 1 SUBJECT MP0317-&amp;amp;SUBJ.";&lt;BR /&gt;proc gplot data=combi2; WHERE USUBJID="&amp;amp;SUBJ" ;&lt;BR /&gt;plot (ASAT ALAT LDH ALP BILIRUBIN BILIRUBIN_DIR BILIRUBIN_INDIR LIPASE)*visit / overlay haxis=axis1 vaxis=axis2&lt;BR /&gt;vref=3 13 cframe=grayee legend;&lt;BR /&gt;plot2 (ASAT ALAT LDH ALP BILIRUBIN BILIRUBIN_DIR BILIRUBIN_INDIR LIPASE)*visit / overlay vaxis=axis3;&lt;BR /&gt;format ASAT ALAT LDH ALP BILIRUBIN BILIRUBIN_DIR BILIRUBIN_INDIR LIPASE 4.1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;axis1 order=(1 to 26 by 1)&lt;BR /&gt;value=(font='Arial/bold' height=8pt)&lt;BR /&gt;offset=(4,4)&lt;BR /&gt;width=2&lt;BR /&gt;label=none&lt;BR /&gt;major=none&lt;BR /&gt;minor=none;&lt;BR /&gt;&lt;BR /&gt;axis2 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL2. by 5)&lt;BR /&gt;label=(angle=90 'x UNL')&lt;BR /&gt;value=(tick=5 ' ' tick=10 ' ')&lt;BR /&gt;offset=(2,2);&lt;BR /&gt;axis3 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL2. by 5)&lt;BR /&gt;label=(angle=90 'x UNL')&lt;BR /&gt;value=(tick=5 ' ' tick=10 ' ')&lt;BR /&gt;offset=(2,2);&lt;BR /&gt;&lt;BR /&gt;symbol4 interpol=join width=1 color=vligb value=dot height=.8;&lt;BR /&gt;symbol5 interpol=join width=1 color=salmon value=dot height=.8;&lt;BR /&gt;symbol6 interpol=join width=1 color=vibg value=dot height=.8;&lt;BR /&gt;&lt;BR /&gt;symbol9 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol10 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;BR /&gt;symbol11 interpol=none value='' font='Arial/bold' color=black height=4pt;&lt;/P&gt;&lt;P&gt;ods excel options(sheet_name="COHORT 1-LAB B");&lt;/P&gt;&lt;P&gt;title1 "MP0317_CRP CK AMYLASE_COHORT 1 SUBJECT MP0317-&amp;amp;SUBJ.";&lt;BR /&gt;proc gplot data=combi2; WHERE USUBJID="&amp;amp;SUBJ" ;&lt;BR /&gt;plot (CRP CK AMYLASE)*visit / overlay haxis=axis1 vaxis=axis2&lt;BR /&gt;vref=3 13 cframe=grayee legend;&lt;BR /&gt;plot2 (CRP CK AMYLASE)*visit / overlay vaxis=axis3 ;&lt;BR /&gt;format CRP CK AMYLASE 4.1;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;ODS EXCEL CLOSE;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;DATA _null_;&lt;BR /&gt;SET COH1;&lt;BR /&gt;CALL EXECUTE (CATS('%nrstr(%gplot)(',USUBJID,')'));&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 11:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852251#M336905</guid>
      <dc:creator>JohanK</dc:creator>
      <dc:date>2023-01-05T11:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852288#M336918</link>
      <description>&lt;P&gt;Hard to read code pasted into the main body of the message instead of using the Insert SAS Code button.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it looks like your logic issue is that you are overwriting the XLSX file by calling the ODS EXCEL statement inside the loop.&amp;nbsp; Instead just open the destination before making the reports and then close when you have finished.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For normal reports where you are writing tabular data to the Excel file you would open the XLSX file once and then perhaps issue separate ODS EXCEL OPTIONS(); statements to change the SHEET name that the next procedure would write to.&amp;nbsp; But I am not sure if that would work with PROC GPLOT.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 15:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852288#M336918</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-05T15:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852300#M336928</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro gplot(subj);

goptions reset=all cback=white border htext=8pt htitle=12pt;

footnote;

axis1 order=(1 to 26 by 1)
value=(font='Arial/bold' height=8pt)
offset=(4,4)
width=2
label=none
major=none
minor=none;

axis2 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL. by 2)
label=(angle=90 'x UNL')
value=(tick=5 ' ' tick=10 ' ')
offset=(2,2);
axis3 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL. by 2)
label=(angle=90 'x UNL')
value=(tick=5 ' ' tick=10 ' ')
offset=(2,2);

symbol1 interpol=join width=1 color=vligb value=dot height=.8;
symbol2 interpol=join width=1 color=salmon value=dot height=.8;
symbol3 interpol=join width=1 color=vibg value=dot height=.8;
symbol4 interpol=join width=1 color=red value=dot height=.8;
symbol5 interpol=join width=1 color=purple value=dot height=.8;
symbol6 interpol=join width=1 color=blue value=dot height=.8;
symbol7 interpol=join width=1 color=yellow value=dot height=.8;
symbol8 interpol=join width=1 color=green value=dot height=.8;

symbol9 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol10 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol11 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol12 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol13 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol14 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol15 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol16 interpol=none value='' font='Arial/bold' color=black height=4pt;
title;


title1 "MP0317_ASAT ALAT LDH ALP BILIRUBIN LIPASE_COHORT 1 SUBJECT MP0317-&amp;amp;SUBJ.";
proc gplot data=combi2; WHERE USUBJID="&amp;amp;SUBJ" ;
plot (ASAT ALAT LDH ALP BILIRUBIN BILIRUBIN_DIR BILIRUBIN_INDIR LIPASE)*visit / overlay haxis=axis1 vaxis=axis2
vref=3 13 cframe=grayee legend;
plot2 (ASAT ALAT LDH ALP BILIRUBIN BILIRUBIN_DIR BILIRUBIN_INDIR LIPASE)*visit / overlay vaxis=axis3;
format ASAT ALAT LDH ALP BILIRUBIN BILIRUBIN_DIR BILIRUBIN_INDIR LIPASE 4.1;
run;

axis1 order=(1 to 26 by 1)
value=(font='Arial/bold' height=8pt)
offset=(4,4)
width=2
label=none
major=none
minor=none;

axis2 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL2. by 5)
label=(angle=90 'x UNL')
value=(tick=5 ' ' tick=10 ' ')
offset=(2,2);
axis3 order=(0 to 1 by .2, 5, 6 to &amp;amp;MAXUNL2. by 5)
label=(angle=90 'x UNL')
value=(tick=5 ' ' tick=10 ' ')
offset=(2,2);

symbol4 interpol=join width=1 color=vligb value=dot height=.8;
symbol5 interpol=join width=1 color=salmon value=dot height=.8;
symbol6 interpol=join width=1 color=vibg value=dot height=.8;

symbol9 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol10 interpol=none value='' font='Arial/bold' color=black height=4pt;
symbol11 interpol=none value='' font='Arial/bold' color=black height=4pt;

ods excel options(sheet_name="COHORT 1-LAB B");

title1 "MP0317_CRP CK AMYLASE_COHORT 1 SUBJECT MP0317-&amp;amp;SUBJ.";
proc gplot data=combi2; WHERE USUBJID="&amp;amp;SUBJ" ;
plot (CRP CK AMYLASE)*visit / overlay haxis=axis1 vaxis=axis2
vref=3 13 cframe=grayee legend;
plot2 (CRP CK AMYLASE)*visit / overlay vaxis=axis3 ;
format CRP CK AMYLASE 4.1;

run;

%mend;

ODS EXCEL FILE = "C:\Users\jkwaaitaal\OneDrive - Molecular Partners AG\Documents\MP0317\MP0317_LAB LIVER_GRAPHICS_%sysfunc(date(),DATE9.).xlsx"
options(embedded_titles='on' sheet_interval='page' sheet_name="COHORT 1-LAB A");
DATA _null_;
SET COH1;
CALL EXECUTE (CATS('%nrstr(%gplot)(',USUBJID,')'));
run;
ODS EXCEL CLOSE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ODS statements are in the wrong location, you're constantly overwriting your file as ODS EXCEL Does not support appending to files.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2023 16:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852300#M336928</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-05T16:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Run a Macro in do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852511#M336984</link>
      <description>&lt;P&gt;Thank you very much Tom!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed from ODS Excel to ODS PDF , and also moved ODS close to the end of the code. It works fantastic!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 15:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Run-a-Macro-in-do-loop/m-p/852511#M336984</guid>
      <dc:creator>JohanK</dc:creator>
      <dc:date>2023-01-06T15:08:39Z</dc:date>
    </item>
  </channel>
</rss>

