<?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: writing a record using a hard-coded value outside a macro works great, but fails inside a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817246#M322580</link>
    <description>&lt;P&gt;Sorry, that extra ) was from a first try using a concatenating function.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jun 2022 08:59:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-06-09T08:59:56Z</dc:date>
    <item>
      <title>writing a record using a hard-coded value outside a macro works great, but fails inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817240#M322576</link>
      <description>&lt;P&gt;This code executes perfectly and creates the string "%let year_hyphen_month = 2021-03; %read_txt()" in the mcalls file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mcalls catalog 'work.mycatalog.mcalls.source' ;
data _null_;
input ;
file mcalls ;
put _infile_ ; 
datalines4 ;
%let year_hyphen_month = 2021-03; %read_txt() 
;;;;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, when I try to run it inside a macro and substitute the hard-coded year-month text (here "2021-03") it fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_data(yrmo);

filename mcalls catalog 'work.mycatalog.mcalls.source' ;
data _null_;
input ;
file mcalls ;
put _infile_ ; 
datalines4 ;
%let year_hyphen_month = &amp;amp;yrmo; %read_txt() 
;;;;
%exit: %mend get_data;
&lt;BR /&gt;%get_data(2021-03)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: The macro GET_DATA generated CARDS (data lines) for the DATA step, which could cause incorrect results.  The DATA step
       and the macro will stop executing.
NOTE: 0 records were written to the file MCALLS.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

ERROR: The macro GET_DATA will stop executing.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I believe there may actually be several issues, starting with use of datalines inside a macro.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried substituting input for datalines, but get a new error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;164  filename mcalls catalog 'work.mycatalog.mcalls.source' ;
165  data _null_;
166  input ;
167  file mcalls ;
168  put _infile_ ;
169  input ;
170  %let year_hyphen_month = 2021-03; %read_txt()
171  ;;;;
172
173  %exit: %mend get_data;
174
175  %get_data(2021-03)
NOTE: Line generated by the invoked macro "GET_DATA".
3     %read_txt() ;;;;
      -
      180
WARNING: Apparent invocation of macro READ_TXT not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 08:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817240#M322576</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2022-06-09T08:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: writing a record using a hard-coded value outside a macro works great, but fails inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817242#M322578</link>
      <description>&lt;P&gt;First of all, you are correct, DATALINES can not be used inside a macro, and macro triggers do not work in DATALINES blocks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a variable code line, use a simple DATA step without DATALINES:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_data(yrmo);

filename mcalls catalog 'work.mycatalog.mcalls.source';

data _null_;
file mcalls ;
length string $100;
string = '%let year_hyphen_month = ' !! "&amp;amp;yrmo" !! '; %read_txt()');
put string;
run;

%mend get_data;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2022 08:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817242#M322578</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-09T08:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: writing a record using a hard-coded value outside a macro works great, but fails inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817244#M322579</link>
      <description>&lt;P&gt;Thanks Kurt (after I fixed the extra ")"&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 08:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817244#M322579</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2022-06-09T08:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: writing a record using a hard-coded value outside a macro works great, but fails inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817246#M322580</link>
      <description>&lt;P&gt;Sorry, that extra ) was from a first try using a concatenating function.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 08:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/writing-a-record-using-a-hard-coded-value-outside-a-macro-works/m-p/817246#M322580</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-09T08:59:56Z</dc:date>
    </item>
  </channel>
</rss>

