<?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 -&amp;gt; Append Macro Variable Values from One Dataset to Another Dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239669#M44125</link>
    <description>Why macro variables? Why not create temp tables that are appended?</description>
    <pubDate>Wed, 16 Dec 2015 23:26:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-16T23:26:08Z</dc:date>
    <item>
      <title>How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239652#M44113</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’m trying to append values of my column on another dataset. I have dataset which includes thousand&amp;nbsp;rows and columns. I prepared a sample dataset as below. Firstly, I want to get values of my column as macro variable then I want to add this values on another dataset. I tried on Want dataset but I couldn’t succeed. The main point is get values of column and append this values row by row. Could you help me, please ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable $ 12 Value 8;
Infile datalines missover dlm=",";
Input Variable Value;
Datalines;
Q1,5
Q2,4
Q3,3
Q4,2
Q5,1
;
Run;
Proc SQL;
/*Create Table Have2 as --&amp;gt; Why this statement doesn't work in the macro variable */ 
Select Variable Into : list separated by " "
From Have;
QUIT;

%Put &amp;amp;list;

Data Want;
Set Have;
NewVariable=&amp;amp;list;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1207i3CBC43A79F660B16/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Desired8.png" title="Desired8.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 22:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239652#M44113</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-16T22:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239658#M44117</link>
      <description>This seems incredibly inefficient, what's the business case for such a method?</description>
      <pubDate>Wed, 16 Dec 2015 22:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239658#M44117</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-16T22:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239662#M44120</link>
      <description>&lt;P&gt;Actually, It is not related to the case, I just need it. The case includes Banking but for the Data&amp;nbsp;Preparation I need it. What does "&lt;SPAN&gt;incredibly inefficient" mean. Is it possible or not ? Or you are thinking it is redundant ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 23:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239662#M44120</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-16T23:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239664#M44122</link>
      <description>Why can't you just use:&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select distinct quarter &lt;BR /&gt;from have&lt;BR /&gt;order by 1;&lt;BR /&gt;quit;</description>
      <pubDate>Wed, 16 Dec 2015 23:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239664#M44122</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-16T23:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239665#M44123</link>
      <description>&lt;P&gt;This is the worst side giving an sample dataset. I can understand you but please don't consider the sample dataset. As I said the main point is&amp;nbsp;&lt;SPAN&gt;get values of column as macro and append this values row by row. I added the sample dataset to be able to see the method.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 23:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239665#M44123</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-16T23:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239669#M44125</link>
      <description>Why macro variables? Why not create temp tables that are appended?</description>
      <pubDate>Wed, 16 Dec 2015 23:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239669#M44125</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-16T23:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239671#M44127</link>
      <description>&lt;P&gt;Okay, I want to learn both methods. Won't it be nice to learn a variety of methods ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 23:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239671#M44127</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-16T23:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239674#M44129</link>
      <description>&lt;P&gt;So how does your actual requirements vary that SELECT DISTINCT doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's a single way to get a list of unique values out, not the only way, proc freq is another way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, I macro's are only useful when:&lt;/P&gt;
&lt;P&gt;• The routine is used more than once.&lt;/P&gt;
&lt;P&gt;• The routine depends on a value of a variable or parameter.&lt;/P&gt;
&lt;P&gt;• The routine requires programming logic that cannot be included in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there some part of your requirements where any of the above become valid?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 23:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239674#M44129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-16T23:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239688#M44136</link>
      <description>&lt;P&gt;I'm not sure I understand what you're trying to do.&amp;nbsp; And I think there are probably better approaches.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That said, maybe you're thinking something like:&lt;/P&gt;&lt;PRE&gt;33   data want;
34     set have;
35     NewVariable=scan("&amp;amp;list",_n_);
36     put (_all_)(=);
37   run;

Variable=Q1 Value=5 NewVariable=Q1
Variable=Q2 Value=4 NewVariable=Q2
Variable=Q3 Value=3 NewVariable=Q3
Variable=Q4 Value=2 NewVariable=Q4
Variable=Q5 Value=1 NewVariable=Q5
NOTE: There were 5 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 5 observations and 3 variables.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the list is too big and you hit problems with scan, you could use a temporary array to hold the values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But why would this be better than just merging on a column?&amp;nbsp; Note that if you want to just smush one variable onto a table ("smush" is my term for a merge with no by-variable matching), you can do that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;53   data want;
54     merge have
55           have(keep=variable rename=(variable=NewVariable))
56     ;
57     *no by;
58     put (_all_)(=);
59   run;

Variable=Q1 Value=5 NewVariable=Q1
Variable=Q2 Value=4 NewVariable=Q2
Variable=Q3 Value=3 NewVariable=Q3
Variable=Q4 Value=2 NewVariable=Q4
Variable=Q5 Value=1 NewVariable=Q5
NOTE: There were 5 observations read from the data set WORK.HAVE.
NOTE: There were 5 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 5 observations and 3 variables&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Dec 2015 02:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239688#M44136</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2015-12-17T02:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239723#M44148</link>
      <description>&lt;P&gt;Thank you for your help. Your approaches can be better for me but I couldn't understand the&lt;/P&gt;
&lt;PRE&gt;put (_all_)(=);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I searched on communites and I found some examples like this one -&amp;gt;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/put-all/td-p/54482." target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/put-all/td-p/54482.&lt;/A&gt; At the following example;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'c:\temp\test.csv' dsd delimiter=";";
  set sashelp.class;
  put (_all_)(+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It puts semicolon&amp;nbsp;between all of the values, isn't it ? On your example, what "&lt;STRONG&gt;put (_all)(=)" &lt;/STRONG&gt;statement&amp;nbsp;do ? Could you explain briefly, please ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2015 09:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239723#M44148</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-17T09:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239743#M44158</link>
      <description>When you have a FILE statement in your step, the PUT statement writes to the file (your example). Without a FILE statement the PUT statement writes to the log (my example). This is often useful for debugging, or in this case just displaying values. It is not a part of the solution.</description>
      <pubDate>Thu, 17 Dec 2015 13:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239743#M44158</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2015-12-17T13:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to -&gt; Append Macro Variable Values from One Dataset to Another Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239760#M44160</link>
      <description>&lt;P&gt;Your requested solution is to create macro variables and append them one by one to a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how that process might work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a macro variable with a list of values - if you can do this, it would easy to dump directly into a data set.&lt;/P&gt;
&lt;P&gt;2. Determine number of values - COUNTW with %sysfunc or a data _null_ step&lt;/P&gt;
&lt;P&gt;3. Create loop for macro variables to loop across each data step. This is the way, especially if you want all the interim data sets.&lt;/P&gt;
&lt;P&gt;4. If first loop, create dataset and Add first variable. If not,&amp;nbsp;To add next value would need to read full dataset, using the END option to indicate last record&lt;/P&gt;
&lt;P&gt;5. Loop to top of macro loop until done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative would be to loop within a data step and use OUTPUT statements to explicitly output variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you can do step 1, you can usually pull them directly into a data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2015 15:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-gt-Append-Macro-Variable-Values-from-One-Dataset-to/m-p/239760#M44160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-17T15:27:46Z</dc:date>
    </item>
  </channel>
</rss>

