<?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: Stack datasets vertically despite different variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/735067#M228976</link>
    <description>&lt;P&gt;One option is to use a SQL Union ALL. The variable names in the combined data set will have the names as per the first select statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  input x y;
  cards;
1 2 
3 4 
5 6
;

data have2;
  input r s;
  cards;
5 6 
7 8 
9 0 
;

proc sql;
  create table combined as
  select x, y
  from have1
  union all
  select r, s
  from have2
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 18 Apr 2021 09:29:05 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-04-18T09:29:05Z</dc:date>
    <item>
      <title>Stack datasets vertically despite different variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/734788#M228892</link>
      <description>data have1;
input x y;
cards;
1 2
3 4
;
run;

 

data have2;
input r s;
cards;
5 6
7 8
9 0
;
run;

data combine;
set have1 have2;
run;

data combine creates a four column dataset.
is there a way to stack have1 and have2 so that have2 is underneath have1
despite having different variable names.  Objective is to only have 2 columns</description>
      <pubDate>Fri, 16 Apr 2021 18:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/734788#M228892</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-04-16T18:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Stack datasets vertically despite different variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/734798#M228897</link>
      <description>&lt;P&gt;Please reformat that example and probably better to place in a text box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use data set options to rename the variables that should align&lt;/P&gt;
&lt;PRE&gt;Data want;
    set one
        two (rename=(r=x s=y))
   ;
run;&lt;/PRE&gt;
&lt;P&gt;for example renames the R to X and S to Y if that is the way you want them aligned (not stated). HOWEVER when you do this it is up to you make sure that the variable types are the same in both sets.&lt;/P&gt;
&lt;P&gt;This rename is one of the data set options can be used anywhere, not just in a data step set statement. Other options can drop or keep variables, subset data and create a number of sometimes useful temporary variables.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 20:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/734798#M228897</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-16T20:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Stack datasets vertically despite different variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/735067#M228976</link>
      <description>&lt;P&gt;One option is to use a SQL Union ALL. The variable names in the combined data set will have the names as per the first select statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  input x y;
  cards;
1 2 
3 4 
5 6
;

data have2;
  input r s;
  cards;
5 6 
7 8 
9 0 
;

proc sql;
  create table combined as
  select x, y
  from have1
  union all
  select r, s
  from have2
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Apr 2021 09:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stack-datasets-vertically-despite-different-variable-names/m-p/735067#M228976</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-18T09:29:05Z</dc:date>
    </item>
  </channel>
</rss>

