<?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 Write Out Macro Variable Values into dataset/file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844848#M333997</link>
    <description>thank alot</description>
    <pubDate>Thu, 17 Nov 2022 13:39:06 GMT</pubDate>
    <dc:creator>hellohere</dc:creator>
    <dc:date>2022-11-17T13:39:06Z</dc:date>
    <item>
      <title>How to Write Out Macro Variable Values into dataset/file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844829#M333992</link>
      <description>&lt;P&gt;I am getting macro variables and need write-out their values into file line-by-line.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Somehow, confused into passing the value into dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Totally alike code is below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	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.";

	data _out_c;
	input line $64.;
	datalines;
	[value]
	age="&amp;amp;val_age."
	height=&amp;amp;val_height.
	weight=&amp;amp;val_weight.
	run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tried various combinations, it does not show up values in dataset _out_c. Anyone?!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 13:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844829#M333992</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-11-17T13:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to Write Out Macro Variable Values into dataset/file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844831#M333993</link>
      <description>&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 class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&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"&gt;Example 12: Using Macro Variables within a CARDS or DATALINES Statement&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 13:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844831#M333993</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T13:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Write Out Macro Variable Values into dataset/file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844839#M333994</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;I am getting macro variables and need write-out their values into file line-by-line.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Somehow, confused into passing the value into dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Totally alike code is below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	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.";

	data _out_c;
	input line $64.;
	datalines;
	[value]
	age="&amp;amp;val_age."
	height=&amp;amp;val_height.
	weight=&amp;amp;val_weight.
	run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tried various combinations, it does not show up values in dataset _out_c. Anyone?!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have to put assignment statements into the CODE of the data step.&amp;nbsp; Not into any in-line source data text.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _out_c;
  age="&amp;amp;val_age.";
  height=&amp;amp;val_height.;
  weight=&amp;amp;val_weight.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to WRITE values then just use the macro variables to generate the PUT statement to WRITE the lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'name_of_file_you_want_to_write' ;
  put  "age=""&amp;amp;val_age."""
     / "height=&amp;amp;val_height."
     / "weight=&amp;amp;val_weight."
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also why are you putting quotes around the AGE value?&amp;nbsp; Is AGE a character variable?&lt;/P&gt;
&lt;P&gt;Also your SQL is inefficient.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select age ,height ,weight
  into :val_age 	
     , :val_height
     , :val_weight
from _temp
having ind=max(ind)
; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 13:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844839#M333994</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-17T13:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to Write Out Macro Variable Values into dataset/file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844847#M333996</link>
      <description>&lt;P&gt;First of all, DATALINES and macro don't go together. Macro triggers in DATALINES are not resolved, and you cannot use DATALINES in a macro.&lt;/P&gt;
&lt;P&gt;DATALINES is always the last statement in a data step and constitutes a step boundary. Therefore, no RUN is needed, and any data step code after it causes a syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks as if you want to use values from the last observation of one dataset in code creating another dataset.&lt;/P&gt;
&lt;P&gt;To retrieve a value from the last observation quickly, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class nobs=nobs point=nobs;
call symputx("val_age",age);
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How you need to use the macro variable depends on the code where it should be used, so please show us that.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 13:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844847#M333996</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-17T13:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to Write Out Macro Variable Values into dataset/file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844848#M333997</link>
      <description>thank alot</description>
      <pubDate>Thu, 17 Nov 2022 13:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Write-Out-Macro-Variable-Values-into-dataset-file/m-p/844848#M333997</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-11-17T13:39:06Z</dc:date>
    </item>
  </channel>
</rss>

