<?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 make DATA/DATALINES work inside a MACRO?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886463#M350280</link>
    <description>&lt;P&gt;What I need is PERIODICALLY to 1) generate macro variables[or another format] 2) write it out into a file, and another&amp;nbsp;&lt;/P&gt;
&lt;P&gt;application will pick it up ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2023 15:32:43 GMT</pubDate>
    <dc:creator>hellohere</dc:creator>
    <dc:date>2023-07-26T15:32:43Z</dc:date>
    <item>
      <title>How to make DATA/DATALINES work inside a MACRO?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886436#M350269</link>
      <description>&lt;P&gt;I have code, generates 4 macro variables and print them out into a file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code works fine, not in a MACRO. When inside MACRO it always complains[see below].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro macroit();
	proc sql noprint;
	select round(md3,0.001) into: val_md3 	from &amp;amp;plotds. having ind=max(ind);
	select round(md3_ema_e,0.001) into: val_md3_ema 	from &amp;amp;plotds. having ind=max(ind);
	select round(md3y,0.001) into: val_md3y 	from &amp;amp;plotds. having ind=max(ind);
	select round(md3y_ema_e,0.001) into: val_md3y_ema 	from &amp;amp;plotds. having ind=max(ind);
	quit;
	%put "val_md3=&amp;amp;val_md3. val_md3y=&amp;amp;val_md3y.";

	data _out_c;
	input mvar $20.;
	val_out_=dequote(resolve(quote(mvar)));
	ind=_N_;
	datalines;
	&amp;amp;val_md3
	&amp;amp;val_md3_ema
	&amp;amp;val_md3y
	&amp;amp;val_md3y_ema
	run;quit;

	data _out_c(keep=val_out_final);
	set _out_c;
	if ind&amp;gt;0 then	val_out_2=substr(mvar,2,length(mvar));
	else val_out_2=mvar;
	if ind&amp;gt;0 then val_out_final=trim(val_out_2)||"="||strip(val_out_);
	else  val_out_final=mvar;
	run;quit;

	data _out_c_0;
	input val_out_final $80.;
	datalines;
	[value]
	run;quit;

	data _out_c; set _out_c_0 _out_c; run;quit;

		proc export data=_out_c(keep=val_out_final)
		OUTFILE='C:\\sinx_out.ini'
		     DBMS=DLM REPLACE;
		     DELIMITER=',';
		     PUTNAMES=NO;
		RUN;
%mend;

%macroit();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
MPRINT(MACROIT):   proc sql noprint;
MPRINT(MACROIT):   select round(md3,0.001) into: val_md3 from _ECL_MD_sin having ind=max(ind);
NOTE: The query requires remerging summary statistics back with the original data.
MPRINT(MACROIT):   select round(md3_ema_e,0.001) into: val_md3_ema from _ECL_MD_sin having ind=max(ind);
NOTE: The query requires remerging summary statistics back with the original data.
MPRINT(MACROIT):   select round(md3y,0.001) into: val_md3y from _ECL_MD_sin having ind=max(ind);
NOTE: The query requires remerging summary statistics back with the original data.
MPRINT(MACROIT):   select round(md3y_ema_e,0.001) into: val_md3y_ema from _ECL_MD_sin having ind=max(ind);
NOTE: The query requires remerging summary statistics back with the original data.
MPRINT(MACROIT):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


MLOGIC(MACROIT):  %PUT "val_md3=&amp;amp;val_md3. val_md3y=&amp;amp;val_md3y."
"val_md3=  -1.193 val_md3y=  -0.884"
MPRINT(MACROIT):   data _out_c;
MPRINT(MACROIT):   input mvar $20.;
MPRINT(MACROIT):   val_out_=dequote(resolve(quote(mvar)));
MPRINT(MACROIT):   ind=_N_;
MPRINT(MACROIT):   datalines;

ERROR: The macro MACROIT 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._OUT_C has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


MPRINT(MACROIT):   - -1.053 -0.884 -0.769 run;
NOTE: Line generated by the macro variable "VAL_MD3".
1               -1.193
                ------
                180

ERROR 180-322: Statement is not valid or it is used out of proper order.

MPRINT(MACROIT):  quit;
MPRINT(MACROIT):   data _out_c(keep=val_out_final);
MPRINT(MACROIT):   set _out_c;
MPRINT(MACROIT):   if ind&amp;gt;0;
MPRINT(MACROIT):  ;
MPRINT(MACROIT):  ;
MPRINT(MACROIT):  ;
ERROR: The macro MACROIT will stop executing.
MLOGIC(MACROIT):  Ending execution.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2023 14:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886436#M350269</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2023-07-26T14:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to make DATA/DATALINES work inside a MACRO?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886450#M350275</link>
      <description>&lt;P&gt;Place the values directly into a data set such as with a CREATE TABLE.&lt;/P&gt;
&lt;P&gt;Combine the data sets generated instead of trying to read the macro variables with input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expect to spend a great deal of time debugging simple problems if you continue to use code like this inside macros:&lt;/P&gt;
&lt;PRE&gt;data _out_c(keep=val_out_final);
	set _out_c;&lt;/PRE&gt;
&lt;P&gt;Since the data set _out_c is completely replaced you cannot tell whether problems came from the data in the Set statement version or were created by code that used that data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you do that TWICE with _out_c just in this code. So any problems that don't throw syntax errors are going to be nasty to find because you will not have a before set to compare with the after.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 14:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886450#M350275</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-26T14:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to make DATA/DATALINES work inside a MACRO?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886453#M350276</link>
      <description>&lt;P&gt;You cannot use datalines inside a macro (the compiled macro no longer has "lines").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what is the purpose of this data step?&lt;/P&gt;
&lt;P&gt;Are you just trying to get the values of series of macro variables?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _out_c;
  length ind 8 mvar $32 val_out $200;
  do mvar='val_md3','val_md3_ema','val_md3y','val_md3y_ema';
    ind+1;
    val_out=symget(mvar);
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2023 15:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886453#M350276</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-26T15:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to make DATA/DATALINES work inside a MACRO?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886463#M350280</link>
      <description>&lt;P&gt;What I need is PERIODICALLY to 1) generate macro variables[or another format] 2) write it out into a file, and another&amp;nbsp;&lt;/P&gt;
&lt;P&gt;application will pick it up ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 15:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886463#M350280</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2023-07-26T15:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to make DATA/DATALINES work inside a MACRO?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886465#M350281</link>
      <description>&lt;P&gt;Does this give you a start:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   create table t1 as
	select round(md3,0.001) asal_md3 	from &amp;amp;plotds. having ind=max(ind);
   create table t2 as
	select round(md3_ema_e,0.001) as val_md3_ema 	from &amp;amp;plotds. having ind=max(ind);
   create table t3 as
	select round(md3y,0.001) as val_md3y 	from &amp;amp;plotds. having ind=max(ind);
   create table t4 as
	select round(md3y_ema_e,0.001) as val_md3y_ema 	from &amp;amp;plotds. having ind=max(ind);
	quit;

data _out_c;
    merge t1 t2 t3 t4;
run;&lt;/PRE&gt;
&lt;P&gt;But this makes no sense at all because you do not provide anywhere that IND gets a value.&lt;/P&gt;
&lt;PRE&gt;data _out_c(keep=val_out_final);
	set _out_c;
	if ind&amp;gt;0 then	&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion:&lt;/P&gt;
&lt;P&gt;Provide an example of a &amp;amp;Plotds data set and the expected file that should be made from it.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 15:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-DATA-DATALINES-work-inside-a-MACRO/m-p/886465#M350281</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-26T15:46:04Z</dc:date>
    </item>
  </channel>
</rss>

