<?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: Macro Error Message in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503937#M134773</link>
    <description>&lt;P&gt;it is apart of the DATA&amp;nbsp; Triangle;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first RUN statement ends the DATA _NULL_ and then the RUN at the bottom the code you pasted is supposed to end the DATA Triangle data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
    <pubDate>Fri, 12 Oct 2018 22:28:19 GMT</pubDate>
    <dc:creator>pchappus</dc:creator>
    <dc:date>2018-10-12T22:28:19Z</dc:date>
    <item>
      <title>Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503902#M134758</link>
      <description>&lt;P&gt;I'm trying to name my columns _2013Q4 _2014Q1 etc. The code works if I use the commented out section towards the bottom but if I use the code with the _&amp;amp;Paid_Qtr., it says the IF statement is out of order.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO Create_Shell();&lt;BR /&gt;DATA Triangle;&lt;BR /&gt;DO n= 1 to &amp;amp;Cols.;&lt;BR /&gt;FORMAT&lt;BR /&gt;INC_MO MMDDYY10.;&lt;BR /&gt;INC_MO = INTNX("MONTH",MDY(MONTH(TODAY()),1,YEAR(TODAY())),n-&amp;amp;Cols.);&lt;BR /&gt;_2013Q3 = 0;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;DATA Triangle;&lt;BR /&gt;SET Triangle;&lt;BR /&gt;%DO s=3 %TO &amp;amp;Cols. - 1 %BY 3;&lt;BR /&gt;%LET x = %EVAL(&amp;amp;Cols. - &amp;amp;s. + 1);&lt;BR /&gt;%LET t = %EVAL(&amp;amp;s. + 1);&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;FORMAT&lt;BR /&gt;PAID_QTR YYQ.;&lt;BR /&gt;PAID_QTR = INTNX("MONTH",MDY(MONTH(TODAY()),1,YEAR(TODAY())) -1,&amp;amp;s. - &amp;amp;Cols.);&lt;BR /&gt;PUT PAID_QTR=;&lt;BR /&gt;PAID_QTR2= PUT(PAID_QTR,YYQ.);&lt;BR /&gt;PUT PAID_QTR2=;&lt;BR /&gt;CALL SYMPUTX('PAID_QTR',PAID_QTR2);&lt;BR /&gt;RUN;&lt;BR /&gt;%PUT &amp;amp;=PAID_QTR;&lt;BR /&gt;IF &amp;amp;x. &amp;gt; _N_ THEN&lt;BR /&gt;_&amp;amp;PAID_QTR. = 0;&lt;BR /&gt;ELSE _&amp;amp;PAID_QTR. = .;&lt;BR /&gt;/* IF &amp;amp;x. &amp;gt; _n_ THEN */&lt;BR /&gt;/* _&amp;amp;t. = 0;*/&lt;BR /&gt;/* ELSE _&amp;amp;t. = .;*/&lt;BR /&gt;%END;&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND Create_Shell;&lt;/P&gt;&lt;P&gt;OPTIONS MPRINT MLOGIC;&lt;BR /&gt;%Create_Shell;&lt;BR /&gt;OPTIONS NOMPRINT NOMLOGIC;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 20:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503902#M134758</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-10-12T20:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503903#M134759</link>
      <description>&lt;P&gt;&amp;amp;Cols. = 60 currently.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 20:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503903#M134759</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-10-12T20:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503905#M134760</link>
      <description>&lt;P&gt;where is the datastep for this part?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RUN;&lt;BR /&gt;%PUT &amp;amp;=PAID_QTR;&lt;BR /&gt;&lt;STRONG&gt;IF &amp;amp;x. &amp;gt; _N_ THEN&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;_&amp;amp;PAID_QTR. = 0;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ELSE _&amp;amp;PAID_QTR. = .;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;/* IF &amp;amp;x. &amp;gt; _n_ THEN */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;/* _&amp;amp;t. = 0;*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;/* ELSE _&amp;amp;t. = .;*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;%END;&lt;/STRONG&gt;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 21:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503905#M134760</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-12T21:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503937#M134773</link>
      <description>&lt;P&gt;it is apart of the DATA&amp;nbsp; Triangle;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first RUN statement ends the DATA _NULL_ and then the RUN at the bottom the code you pasted is supposed to end the DATA Triangle data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 22:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503937#M134773</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-10-12T22:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503938#M134774</link>
      <description>&lt;P&gt;Nope,&amp;nbsp;when a data step encounters another DATA statement that serves as a RUN and closes the first step. Your RUN statements are incorrectly set and you cannot have nested DATA Steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is more clear when you format your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO Create_Shell();
    DATA Triangle;
        DO n=1 to &amp;amp;Cols.;
            FORMAT INC_MO MMDDYY10.;
            INC_MO=INTNX("MONTH", MDY(MONTH(TODAY()), 1, YEAR(TODAY())), n-&amp;amp;Cols.);
            _2013Q3=0;
            OUTPUT;
        END;
    RUN;

    DATA Triangle;
        SET Triangle;

        %DO s=3 %TO &amp;amp;Cols. - 1 %BY 3;
            %LET x = %EVAL(&amp;amp;Cols. - &amp;amp;s. + 1);
            %LET t = %EVAL(&amp;amp;s. + 1);

        &lt;FONT size="5" color="#800080"&gt;&lt;STRONG&gt;DATA _NULL_; *ends data triangle step;&lt;/STRONG&gt;&lt;/FONT&gt;
            FORMAT PAID_QTR YYQ.;
            PAID_QTR=INTNX("MONTH", MDY(MONTH(TODAY()), 1, YEAR(TODAY())) -1, 
                &amp;amp;s. - &amp;amp;Cols.);
            PUT PAID_QTR=;
            PAID_QTR2=PUT(PAID_QTR, YYQ.);
            PUT PAID_QTR2=;
            CALL SYMPUTX('PAID_QTR', PAID_QTR2);
        &lt;FONT size="5" color="#800080"&gt;&lt;STRONG&gt;RUN; *ends _null_ step;&lt;/STRONG&gt;&lt;/FONT&gt;

        %PUT &amp;amp;=PAID_QTR;
       &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; IF &amp;amp;x. &amp;gt; _N_ THEN _&amp;amp;PAID_QTR.=0; *open invalid data step code;
        ELSE _&amp;amp;PAID_QTR.=.;
&lt;/STRONG&gt;&lt;/FONT&gt;
        /* IF &amp;amp;x. &amp;gt; _n_ THEN */
        /* _&amp;amp;t. = 0;*/
        /* ELSE _&amp;amp;t. = .;*/
%END;
    RUN;
%MEND Create_Shell;

OPTIONS MPRINT MLOGIC;
%Create_Shell;
OPTIONS NOMPRINT NOMLOGIC;&lt;/CODE&gt;&lt;/PRE&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/212034"&gt;@pchappus&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;it is apart of the DATA&amp;nbsp; Triangle;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first RUN statement ends the DATA _NULL_ and then the RUN at the bottom the code you pasted is supposed to end the DATA Triangle data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Paul&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 22:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503938#M134774</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-12T22:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503945#M134775</link>
      <description>&lt;P&gt;Use indentation to format your code to make it clearer.&amp;nbsp; I like the set the indentation of macro statements independently from the indentation of the actual SAS code that the macro is generating.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro create_shell();
data triangle;
  do n= 1 to &amp;amp;cols.;
    format inc_mo mmddyy10.;
    inc_mo = intnx("month",mdy(month(today()),1,year(today())),n-&amp;amp;cols.);
    _2013q3 = 0;
    output;
  end;
run;

data triangle;
  set triangle;

%do s=3 %to &amp;amp;cols. - 1 %by 3;
  %let x = %eval(&amp;amp;cols. - &amp;amp;s. + 1);
  %let t = %eval(&amp;amp;s. + 1);

data _null_;
  format paid_qtr yyq.;
  paid_qtr = intnx("month",mdy(month(today()),1,year(today())) -1,&amp;amp;s. - &amp;amp;cols.);
  put paid_qtr=;
  paid_qtr2= put(paid_qtr,yyq.);
  put paid_qtr2=;
  call symputx('paid_qtr',paid_qtr2);
run;

  %put &amp;amp;=paid_qtr;

if &amp;amp;x. &amp;gt; _n_ then_&amp;amp;paid_qtr. = 0;
else _&amp;amp;paid_qtr. = .;

%end;
run;
%mend create_shell;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That way it is easy to see that you have two line data step that does nothing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data triangle;
  set triangle;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will end if the %DO loop runs at least once and generates other steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And also an IF statements detached from any data step at the end of your %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;x. &amp;gt; _n_ then_&amp;amp;paid_qtr. = 0;
else _&amp;amp;paid_qtr. = .;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and an extra RUN statement after the %DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 23:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503945#M134775</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-12T23:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503947#M134777</link>
      <description>&lt;P&gt;Before you start writing a macro to generate SAS code figure out what SAS code you want to generate.&lt;/P&gt;
&lt;P&gt;I looks like you are playing with the same triangle matrix generating step, but now you want to generate variable names that contain dates in them.&amp;nbsp;&amp;nbsp;So first figure out what code you want to generate.&amp;nbsp; As I said on your other question you don't need macro code to generate your matrix.&amp;nbsp; Just use an ARRAY statement.&amp;nbsp; &amp;nbsp;If you want to make the variable names dynamic then use a macro variable to hold the list of names.&amp;nbsp; You can use a data step to generate the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say you want to generate these variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array cols Y2018Q4 Y2019Q1 Y2019Q2 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could run this data step to generate a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length varlist $1000;
  do offset=0 to &amp;amp;cols -1 ;
    date = intnx('qtr',today(),offset);
    varlist=catx(' ',varlist,cats('Y',put(date,yyq.)));
  end;
  call symputx('varlist',varlist);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then your ARRAY statement can be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array cols &amp;amp;varlist;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 23:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503947#M134777</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-12T23:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503962#M134786</link>
      <description>&lt;P&gt;I think I will eventually end up going the array route but using this as a learning opportunity to do it the more complicated way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 00:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503962#M134786</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-10-13T00:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Error Message</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503963#M134787</link>
      <description>&lt;P&gt;Okay that makes since, I need to figure out a way to have the loop create the column names without doing a data null step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason, when ever I paste my code it takes away all my formatting I have in the program.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 00:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Error-Message/m-p/503963#M134787</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-10-13T00:59:58Z</dc:date>
    </item>
  </channel>
</rss>

