<?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 put the codes into a macro?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981406#M379113</link>
    <description>&lt;P&gt;Thanks all. Everyone gave the answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found an detour: create the initial dataset somewhere else, and just copy it at the start of iteration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;%macro init_er();&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; data _xtemp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; set trxtb._xtemp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; run;quit;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%mend;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%init_er();&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jan 2026 05:40:35 GMT</pubDate>
    <dc:creator>hellohere</dc:creator>
    <dc:date>2026-01-01T05:40:35Z</dc:date>
    <item>
      <title>How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981385#M379102</link>
      <description>&lt;P&gt;I am confused here. Simply the dataset code lines work itself.&amp;nbsp; It does not complain, and the dataset is created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _xtemp;
	input endrange;
	datalines;
	-100
	-75
	-50
	-30
	-20
	-10
	0
	10
	20
	30
	40
	50
	60
	80
	100
	125 
	150
	200
	250
	300
	350
	400
	500
	600
	;
	run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;5709  data _xtemp;
5710      input endrange;
5711      datalines;

NOTE: The data set WORK._XTEMP has 24 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BUT, if put into a macro, it complains !!! I do need these lines inside a macro .&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro init_er();
	data _xtemp;
	input endrange;
	datalines;
	-100
	-75
	-50
	-30
	-20
	-10
	0
	10
	20
	30
	40
	50
	60
	80
	100
	125 
	150
	200
	250
	300
	350
	400
	500
	600
	;
	run;quit;

%mend;

%init_er();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;5675  %macro init_er();
5676      data _xtemp;
5677      input endrange;
5678      datalines;
5679      -100
5680      -75
5681      -50
5682      -30
5683      -20
5684      -10
5685      0
5686      10
5687      20
5688      30
5689      40
5690      50
5691      60
5692      80
5693      100
5694      125
5695      150
5696      200
5697      250
5698      300
5699      350
5700      400
5701      500
5702      600
5703      ;
5704      run;quit;
5705
5706  %mend;
5707
5708  %init_er();
MLOGIC(INIT_ER):  Beginning execution.
MPRINT(INIT_ER):   data _xtemp;
MPRINT(INIT_ER):   input endrange;
MPRINT(INIT_ER):   datalines;

ERROR: The macro INIT_ER generated CARDS (data lines) for the DATA step, which could cause incorrect results.  The DATA step and the macro
       will stop executing.
NOTE: The data set WORK._XTEMP has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


MPRINT(INIT_ER):   - -75 -50 -30 -20 -10 0 10 20 30 40 50 60 80 100 125 150 200 250 300 350 400 500 600 ;
NOTE: Line generated by the invoked macro "INIT_ER".
1                                                           -100     -75     -50     -30     -20     -10     0     10     20     30     40
                                                            ----
                                                            180
1   !    50     60     80     100     125     150     200     250     300     350     400     500     600     ;     run

ERROR 180-322: Statement is not valid or it is used out of proper order.

MPRINT(INIT_ER):   run;
MPRINT(INIT_ER):  ;
MPRINT(INIT_ER):  ;
MPRINT(INIT_ER):  ;
ERROR: The macro INIT_ER will stop executing.
MLOGIC(INIT_ER):  Ending execution.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Dec 2025 11:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981385#M379102</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2025-12-31T11:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981387#M379103</link>
      <description>&lt;P&gt;I DO need the code lines, to generate the simple dataset, inside&amp;nbsp; a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset has a single column, ENDRANGE. I am to run a loop to collect the impact from endrange on experiments. The endranges will go though excluasion by criteria from other macro variables. So each time the dataset need re-created at the start[then go exclusion, ...].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 12:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981387#M379103</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2025-12-31T12:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981393#M379106</link>
      <description>&lt;P&gt;You can't use DATALINES; or CARDS; inside a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a loop in a macro, maybe something like this works for you (UNTESTED CODE)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
    %let endranges = -100 -75 -50  -30 -20;  /* I'm lazy, you can type the rest */
    %do i=1 %to %sysfunc(countw(&amp;amp;endranges,%str( )));
        %let this_endrange=%scan(&amp;amp;endranges,&amp;amp;i,%str( ));
        /* Put the code here to perform whatever tasks you want on macro variable &amp;amp;this_endrange */
    %end;
%mend;
%dothis
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 12:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981393#M379106</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-12-31T12:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981395#M379108</link>
      <description>&lt;P&gt;Yes. You are unable to include CARDS or DATALINES statement in a macro. This limited thing has been mentioned in sas documentation.&amp;nbsp; You would either include these data in a file or hard code these data like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro init_er();

	data _xtemp;
	 endrange=-100 ; output;
	 endrange=-75  ; output;
	 endrange=-50  ; output;
	;
	run;

%mend;

%init_er();&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Dec 2025 13:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981395#M379108</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-12-31T13:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981396#M379109</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;The endranges will go though excluasion by criteria from other macro variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you do have a &lt;EM&gt;rule&lt;/EM&gt; to create the datalines. Just put this rule into data step code.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 14:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981396#M379109</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-12-31T14:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981400#M379110</link>
      <description>&lt;P&gt;This usage note explains the issue:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/43/902.html" target="_blank"&gt;https://support.sas.com/kb/43/902.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With Notepad++ you can modify your code a bit:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro init_er();
data _xtemp;
  endrange = -100; output;
  endrange = -75 ; output;
  endrange = -50 ; output;
  endrange = -30 ; output;
  endrange = -20 ; output;
  endrange = -10 ; output;
  endrange = 0   ; output;
  endrange = 10  ; output;
  endrange = 20  ; output;
  endrange = 30  ; output;
  endrange = 40  ; output;
  endrange = 50  ; output;
  endrange = 60  ; output;
  endrange = 80  ; output;
  endrange = 100 ; output;
  endrange = 125 ; output;
  endrange = 150 ; output;
  endrange = 200 ; output;
  endrange = 250 ; output;
  endrange = 300 ; output;
  endrange = 350 ; output;
  endrange = 400 ; output;
  endrange = 500 ; output;
  endrange = 600 ; output;
run;

%mend;

%init_er();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 15:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981400#M379110</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-12-31T15:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981403#M379112</link>
      <description>&lt;P&gt;You cannot use in-line data inside a macro.&amp;nbsp; Once the macro is compiled into the word token the concept of a LINE of data is gone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you don't need the datalines, you need the dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So generate the data some other way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _xtemp;
  do endrange
    =-100
    ,-75
    ,-50
    ,-30
    ,-20
    ,-10
    ,0
    ,10
    ,20
    ,30
    ,40
    ,50
    ,60
    ,80
    ,100
    ,125 
    ,150
    ,200
    ,250
    ,300
    ,350
    ,400
    ,500
    ,600
  ;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also use the TO and BY keywords to save some typing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _xtemp;
  do endrange=-100,-75,-50
    ,-30 to 60 by 10
    ,80,100,125
    ,150 to 400 by 50
    ,500,600
  ;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Dec 2025 18:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981403#M379112</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-31T18:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981406#M379113</link>
      <description>&lt;P&gt;Thanks all. Everyone gave the answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found an detour: create the initial dataset somewhere else, and just copy it at the start of iteration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;%macro init_er();&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; data _xtemp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; set trxtb._xtemp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; run;quit;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%mend;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%init_er();&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jan 2026 05:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981406#M379113</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2026-01-01T05:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981415#M379115</link>
      <description>&lt;P&gt;If you're doing it this way, do it smarter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro init_er();

%if NOT %sysfunc(exist(trxtb._xtemp)) %then
  %do;
    %put ERROR: trxtb._xtemp does NOT exist! Exiting.;
    %return;
  %end;

data _xtemp;
set trxtb._xtemp;
run;quit;
 
%mend;
 
%init_er()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jan 2026 11:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981415#M379115</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2026-01-01T11:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to put the codes into a macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981416#M379116</link>
      <description>&lt;P&gt;Why so complicated?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why create a temporary data set named _XTEMP?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Why not just use the data set&amp;nbsp;TRXTB._XTEMP in the macro?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jan 2026 11:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-the-codes-into-a-macro/m-p/981416#M379116</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-01-01T11:35:38Z</dc:date>
    </item>
  </channel>
</rss>

