<?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: Error with datalines resolving macrovariables inside a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497277#M131751</link>
    <description>&lt;P&gt;Why would you need to create test data inside a macro in the first place?&amp;nbsp; Macro is not a replacement for Base SAS, it is an extra component for a specific purpose, only use it when it actually adds something to the code, which in this case it doesn't.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 08:36:49 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-09-20T08:36:49Z</dc:date>
    <item>
      <title>Error with datalines resolving macrovariables inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497265#M131744</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a dataset from scratch with datalines using to feed it some values contained in macrovariables that I want to define as arguments of a macro. I was first trying this code outside the macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let study = aaa bbb;
%let protocol = ccc ddd;
%let cutoff = eee fff;
%let rationale = ggg hhh;

		data _auxsummary;
		   	input studyi $8. protocoli $11. cutoffi $8. rationalei $11.;
		    /* The RESOLVE function is used so that the ampersand within the */
  			/* value of text is treated as a macro variable.                 */
  			studyr=dequote(resolve(quote(studyi)));
			protocolr=dequote(resolve(quote(protocoli)));
			cutoffr=dequote(resolve(quote(cutoffi)));
			rationaler=dequote(resolve(quote(rationalei)));
		   datalines;
		&amp;amp;study &amp;amp;protocol &amp;amp;cutoff &amp;amp;rationale
		;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and it is working fine. &lt;STRONG&gt;&amp;amp;variable&lt;/STRONG&gt; are the macrovariables, &lt;STRONG&gt;variablei&lt;/STRONG&gt; are the input ones in the datalines data step and &lt;STRONG&gt;varaibler&lt;/STRONG&gt; are the ones containing the resolved macrovariable value. You can check here the output data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23406i4CA0C7F17D9B92A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the next step I just want to report the resolved values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If now I include this piece of code in a macro and execute it, it is not longer working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macro_test(
		study = 
		,protocol = 
		,cutoff =  
		,rationale = );

		data _auxsummary;
		   	input studyi $8. protocoli $11. cutoffi $8. rationalei $11.;
		    /* The RESOLVE function is used so that the ampersand within the */
  			/* value of text is treated as a macro variable.                 */
  			studyr=dequote(resolve(quote(studyi)));
			protocolr=dequote(resolve(quote(protocoli)));
			cutoffr=dequote(resolve(quote(cutoffi)));
			rationaler=dequote(resolve(quote(rationalei)));
		   datalines;
		&amp;amp;study &amp;amp;protocol &amp;amp;cutoff &amp;amp;rationale
		;

%mend;

%macro_test(
		study = aaa bbb
		,protocol = ccc ddd
		,cutoff = eee fff 
		,rationale = ggg hhh);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;MLOGIC(MACRO_TEST): Beginning execution.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;study = aaa bbb&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;,protocol = ccc ddd&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;,cutoff = eee fff&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;,rationale = ggg hhh);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MLOGIC(MACRO_TEST): Parameter STUDY has value aaa bbb&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;The SAS System&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;MLOGIC(MACRO_TEST): Parameter PROTOCOL has value ccc ddd&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MLOGIC(MACRO_TEST): Parameter CUTOFF has value eee fff&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MLOGIC(MACRO_TEST): Parameter RATIONALE has value ggg hhh&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): data _auxsummary;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): input studyi $8. protocoli $11. cutoffi $8. rationalei $11.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): studyr=dequote(resolve(quote(studyi)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): protocolr=dequote(resolve(quote(protocoli)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): cutoffr=dequote(resolve(quote(cutoffi)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): rationaler=dequote(resolve(quote(rationalei)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MPRINT(MACRO_TEST): datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;ERROR: The macro MACRO_TEST generated CARDS (data lines) for the DATA step, which could cause incorrect results. The DATA step and the macro will stop executing.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong? Maybe I'm making easy things difficult, is there any other way to accomplish what I need?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for any tips or suggestions!!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 07:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497265#M131744</guid>
      <dc:creator>emera86</dc:creator>
      <dc:date>2018-09-20T07:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error with datalines resolving macrovariables inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497271#M131746</link>
      <description>&lt;P&gt;DATALINES are explicitly not allowed inside a macro: &lt;A href="http://support.sas.com/kb/43/902.html" target="_blank"&gt;http://support.sas.com/kb/43/902.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 08:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497271#M131746</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-09-20T08:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Error with datalines resolving macrovariables inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497277#M131751</link>
      <description>&lt;P&gt;Why would you need to create test data inside a macro in the first place?&amp;nbsp; Macro is not a replacement for Base SAS, it is an extra component for a specific purpose, only use it when it actually adds something to the code, which in this case it doesn't.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 08:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497277#M131751</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-20T08:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error with datalines resolving macrovariables inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497306#M131765</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The general purpose of the macro (this code that I'm showing is just a little piece) is to generate an extense report. At the beginning of this report I would like to add some general info related to the the specific project in table format. That is why I wanted to create it from some of the macro arguments. You are right, is not a clean way to do it (maybe you or other could suggest another way). I could create this table in advance and feed the macro with it, but I think that including these parameters as arguments of the macro will make it more easy to use for future users. What do you think?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your comment anyway.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 11:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497306#M131765</guid>
      <dc:creator>emera86</dc:creator>
      <dc:date>2018-09-20T11:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Error with datalines resolving macrovariables inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497331#M131780</link>
      <description>&lt;P&gt;Since this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _auxsummary;
		   	input studyi $8. protocoli $11. cutoffi $8. rationalei $11.;
		    /* The RESOLVE function is used so that the ampersand within the */
  			/* value of text is treated as a macro variable.                 */
  			studyr=dequote(resolve(quote(studyi)));
			protocolr=dequote(resolve(quote(protocoli)));
			cutoffr=dequote(resolve(quote(cutoffi)));
			rationaler=dequote(resolve(quote(rationalei)));
		   datalines;
		&amp;amp;study &amp;amp;protocol &amp;amp;cutoff &amp;amp;rationale
		;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the equivalent of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _auxsummary;
studyr = "&amp;amp;study";
protocolr = "&amp;amp;protocol";
cutoffr = "&amp;amp;cutoff";
rationaler = "&amp;amp;rationalei";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it's just an unnecessary (and stupid) way of obfuscating code.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497331#M131780</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-20T12:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error with datalines resolving macrovariables inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497368#M131806</link>
      <description>&lt;P&gt;You are totally right&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, as I was suspecting I was trying to solve a simple problem in a complex (and stupid) way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 14:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-datalines-resolving-macrovariables-inside-a-macro/m-p/497368#M131806</guid>
      <dc:creator>emera86</dc:creator>
      <dc:date>2018-09-20T14:13:20Z</dc:date>
    </item>
  </channel>
</rss>

