<?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 How to concatenate two files with some specific columns? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735140#M229004</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets named have1 and have2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both datasets have 4 columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x1 x2 x3 c4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;while&lt;STRONG&gt; x1,x3&lt;/STRONG&gt; are numeric and &lt;STRONG&gt;c&lt;/STRONG&gt; is character. Now I only want to concatenate these two datasets without column x2 (because it was numeric in dataset have 1 but character in have2), I mean the concatenated dataset is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x1 x3 c4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My code to do concatenate in normal condition (without dropping x2) is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data concatenate_;
length x1 8 x2 8 x3 8 c4 $100;
set have1 have2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you please help me to sort it out, thank you! Or in another word, how to concatenate two files with only some specific columns?&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Apr 2021 23:37:05 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-04-18T23:37:05Z</dc:date>
    <item>
      <title>How to concatenate two files with some specific columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735140#M229004</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets named have1 and have2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both datasets have 4 columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x1 x2 x3 c4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;while&lt;STRONG&gt; x1,x3&lt;/STRONG&gt; are numeric and &lt;STRONG&gt;c&lt;/STRONG&gt; is character. Now I only want to concatenate these two datasets without column x2 (because it was numeric in dataset have 1 but character in have2), I mean the concatenated dataset is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x1 x3 c4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My code to do concatenate in normal condition (without dropping x2) is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data concatenate_;
length x1 8 x2 8 x3 8 c4 $100;
set have1 have2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you please help me to sort it out, thank you! Or in another word, how to concatenate two files with only some specific columns?&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 23:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735140#M229004</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-04-18T23:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate two files with some specific columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735144#M229007</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data concatenate_ (keep = x1 x3 c4);
length x1 8 x2 8 x3 8 c4 $100;
set have1 have2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Apr 2021 23:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735144#M229007</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-18T23:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate two files with some specific columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735145#M229008</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see what you mean. Sorry I did not explain well. What I want is I do not want SAS to perform concatenating on x2 (because the types of x2 are mixed: it was numeric in have1 but character in have2)..&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 23:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735145#M229008</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-04-18T23:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate two files with some specific columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735148#M229009</link>
      <description>&lt;P&gt;Below some options&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data concatenate_;
length x1 8 x3 8 c4 $100;
set have1(keep=x1 x3 c4) have2 (keep=x1 x3 c4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table combined as
  select x1,x3,c4
  from have1
  union all corr
  select x1,x3,c4
  from have2
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you want to keep x2 as character (in example below assumed numeric in have2)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table combined as
  select x1,x3,c4, x2
  from have1
  union all corr
  select x1,x3,c4, put(x2, 32.) as x2 length=16
  from have2
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you could also convert the character to numeric if the data allow for it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table combined as
  select x1,x3,c4, input(x2, best32.) as x2
  from have1
  union all corr
  select x1,x3,c4, x2
  from have2
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and to add to above: Using a SAS UNION will for character variables in the target table use the max length of the variable coming from the sources so you never risk data truncation if lengths differ.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 23:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-two-files-with-some-specific-columns/m-p/735148#M229009</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-18T23:51:58Z</dc:date>
    </item>
  </channel>
</rss>

