<?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 use CARD/DATALINES inside Macro?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844912#M334022</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;in your other thread, you marked correct an answer from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;which said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Why do you want to do this? Seems to be part of a bigger problem? In that case, describe your actual problem. There is probably a better way than this&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your question is merely related to using macro variables in cards/datalines, read&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p10yr6jbpc8t6dn1xurxomzg37fl.htm" target="_self" rel="nofollow noopener noreferrer"&gt;Example 12: Using Macro Variables within a CARDS or DATALINES Statement&lt;/A&gt;.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have totally ignored this answer, which you marked as correct. Please explain your overall goal, explain WHY you are doing this and what you hope to achieve, as stated above. None of this requires code, give us an answer in words that explains the project and what you are trying to do. It is hard to see how to make progress until we get this explanation from you, and several people have asked. Don't keep asking the same question in a different thread — explain.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 17:33:53 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-11-17T17:33:53Z</dc:date>
    <item>
      <title>HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844908#M334020</link>
      <description>&lt;P&gt;I tried to use CARD/DATALINES inside a macro, and somehow complains. How to de-route this?! Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loopit();
	data _temp;
	set sashelp.class;
	ind=_N_;
	run;quit;
	proc sql noprint;
	select age into: val_age 	from _temp having ind=max(ind); 
	select height into: val_height 	from _temp having ind=max(ind); 
	select weight into: val_weight 	from _temp having ind=max(ind); 
	quit;
	%put "val_age=&amp;amp;val_age.";

/*working below*/	
data _out_c;
input mvar $16.;
val_out_=dequote(resolve(quote(mvar)));
ind=_N_;
datalines;
[value]
&amp;amp;val_age
&amp;amp;val_height
&amp;amp;val_weight
run;quit;

	data _out_c;
	set _out_c;
	if ind&amp;gt;1 then	val_out_2=substr(mvar,2,length(mvar));
	else val_out_2=mvar;
	if ind&amp;gt;1 then val_out_final=trim(val_out_2)||"="||strip(val_out_);
	else  val_out_final=mvar;
	run;quit;
%mend;

%loopit();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MPRINT(LOOPIT):   data _out_c;
MPRINT(LOOPIT):   input mvar $16.;
MPRINT(LOOPIT):   val_out_=dequote(resolve(quote(mvar)));
MPRINT(LOOPIT):   ind=_N_;
MPRINT(LOOPIT):   datalines;

ERROR: The macro LOOPIT 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
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 16:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844908#M334020</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-11-17T16:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844910#M334021</link>
      <description>&lt;P&gt;Cards/Datalines are not supported in macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you're selecting the last row? I'm assuming since it's a max could possibly return multiple values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are much simpler ways of doing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this seems like a &lt;A href="https://xyproblem.info/" target="_self"&gt;XY problem&lt;/A&gt;, what are you trying to accomplish here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 16:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844910#M334021</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-17T16:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844912#M334022</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;in your other thread, you marked correct an answer from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;which said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Why do you want to do this? Seems to be part of a bigger problem? In that case, describe your actual problem. There is probably a better way than this&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your question is merely related to using macro variables in cards/datalines, read&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p10yr6jbpc8t6dn1xurxomzg37fl.htm" target="_self" rel="nofollow noopener noreferrer"&gt;Example 12: Using Macro Variables within a CARDS or DATALINES Statement&lt;/A&gt;.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have totally ignored this answer, which you marked as correct. Please explain your overall goal, explain WHY you are doing this and what you hope to achieve, as stated above. None of this requires code, give us an answer in words that explains the project and what you are trying to do. It is hard to see how to make progress until we get this explanation from you, and several people have asked. Don't keep asking the same question in a different thread — explain.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 17:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844912#M334022</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-17T17:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844920#M334027</link>
      <description>&lt;P&gt;If you want to make a dataset with the values your SQL is selecting then why not just make the dataset with the SQL code that is selecting those values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table _out_c as 
  select age,height,weight
  from _temp
  having ind=max(ind)
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you want to find the last observation in a dataset just use a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _out_c;
  set sashelp.class end=eof;
  if eof;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 16:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844920#M334027</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-17T16:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844927#M334032</link>
      <description>&lt;P&gt;Well, I did take the link to code correctly, without macro, to pass macro variables to DATALINES/DATA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is for production. What I need is to generate a text file(will be read by C++ code):&lt;/P&gt;
&lt;P&gt;This 1st line, [value]&lt;/P&gt;
&lt;P&gt;The 2nd/3rd/.. line: variable_name=variable's value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not need the values at each column. I need them with the format above, line-by-line.&lt;/P&gt;
&lt;P&gt;Coding without Macro Loopit(), run well. But I need overwrite the file every n-second(values are updated),&lt;/P&gt;
&lt;P&gt;so I use MACRO(I skip the do-loop in my macro), but seem MACRO does not allow DATALINES/DATA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how to generate the file, periodically?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 17:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844927#M334032</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-11-17T17:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844929#M334033</link>
      <description>I see your code. It surely is better than mine. Thanks, 

I am more on whether/how it works.</description>
      <pubDate>Thu, 17 Nov 2022 17:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844929#M334033</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-11-17T17:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844931#M334035</link>
      <description>&lt;P&gt;That is pretty trivial format to reproduce.&lt;/P&gt;
&lt;P&gt;Let's take the first observation of SASHELP.CLASS as an example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename outfile temp;

data _null_;
  set sashelp.class (obs=1);
  file outfile ;
  put '[value]' (_all_) (=/);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resulting file:&lt;/P&gt;
&lt;PRE&gt;[value]
Name=Alfred
Sex=M
Age=14
Height=69
Weight=112.5
&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 18:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844931#M334035</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-17T18:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: HOW to use CARD/DATALINES inside Macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844948#M334046</link>
      <description>Wow, this is super neat and clean.</description>
      <pubDate>Thu, 17 Nov 2022 19:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/HOW-to-use-CARD-DATALINES-inside-Macro/m-p/844948#M334046</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-11-17T19:24:44Z</dc:date>
    </item>
  </channel>
</rss>

