<?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: Concatenate a variable, can i then reverse the process? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59498#M12898</link>
    <description>Charles,&lt;BR /&gt;
I'd recommend an SQL solution as easier to code.  Consider this code:&lt;BR /&gt;
&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
/*Create two data sets to play with*/&lt;BR /&gt;
data DS1;&lt;BR /&gt;
   LENGTH Text $1 Num 8 DS1 $1;&lt;BR /&gt;
   DS1="X";&lt;BR /&gt;
   do Text= "A","B","C";&lt;BR /&gt;
      do Num=1 to 2;&lt;BR /&gt;
         output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
data DS2;&lt;BR /&gt;
   LENGTH Text $1 Num 8 DS2 $1;&lt;BR /&gt;
   DS2="X";&lt;BR /&gt;
   do Text= "A","C";&lt;BR /&gt;
      do Num=1 to 5;&lt;BR /&gt;
         output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* SQL solution */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table Merged_sql as&lt;BR /&gt;
select coalesce(A.TEXT,B.TEXT,"") AS Text&lt;BR /&gt;
     , coalesce(a.Num,B.Num) as Num&lt;BR /&gt;
     , DS1&lt;BR /&gt;
     , DS2&lt;BR /&gt;
   from ds1 as a&lt;BR /&gt;
     full JOIN &lt;BR /&gt;
   ds2 as b&lt;BR /&gt;
   on a.Text=b.Text and a.Num=b.num&lt;BR /&gt;
   ;&lt;BR /&gt;
quit;&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
&lt;BR /&gt;
You can produce the same results with the following data step code &amp;amp; concatenating variables:&lt;BR /&gt;
&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
/*Data Step Solution*/&lt;BR /&gt;
data DS1a;&lt;BR /&gt;
   set DS1;&lt;BR /&gt;
   _joinvar=CATX(Text,Num);&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=DS1a;&lt;BR /&gt;
   by _joinvar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data DS2a;&lt;BR /&gt;
   set DS2;&lt;BR /&gt;
   _joinvar=CATX(Text,Num);&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=DS2a;&lt;BR /&gt;
   by _joinvar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data Merged_data_step;&lt;BR /&gt;
   merge DS1a &lt;BR /&gt;
         DS2a ;&lt;BR /&gt;
   by _joinvar;&lt;BR /&gt;
   drop _joinvar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=merged_data_step;&lt;BR /&gt;
   by Text Num;&lt;BR /&gt;
run;&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps!</description>
    <pubDate>Fri, 29 Apr 2011 02:08:57 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2011-04-29T02:08:57Z</dc:date>
    <item>
      <title>Concatenate a variable, can i then reverse the process?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59496#M12896</link>
      <description>I'm concatenating a variable to make the process of merging 2 datasets together go a lot faster, but once this is done, i'd really like to get things back to the original variables.  Is this possible?</description>
      <pubDate>Thu, 28 Apr 2011 18:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59496#M12896</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-28T18:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a variable, can i then reverse the process?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59497#M12897</link>
      <description>Charles,&lt;BR /&gt;
&lt;BR /&gt;
There are at least two answers.  One, you don't have to drop the original variables in the first place.  Two, if you concatenate with a uniques separator (e.g., a |), you can always use the scan function to deconcatenate.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 28 Apr 2011 19:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59497#M12897</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T19:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a variable, can i then reverse the process?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59498#M12898</link>
      <description>Charles,&lt;BR /&gt;
I'd recommend an SQL solution as easier to code.  Consider this code:&lt;BR /&gt;
&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
/*Create two data sets to play with*/&lt;BR /&gt;
data DS1;&lt;BR /&gt;
   LENGTH Text $1 Num 8 DS1 $1;&lt;BR /&gt;
   DS1="X";&lt;BR /&gt;
   do Text= "A","B","C";&lt;BR /&gt;
      do Num=1 to 2;&lt;BR /&gt;
         output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
data DS2;&lt;BR /&gt;
   LENGTH Text $1 Num 8 DS2 $1;&lt;BR /&gt;
   DS2="X";&lt;BR /&gt;
   do Text= "A","C";&lt;BR /&gt;
      do Num=1 to 5;&lt;BR /&gt;
         output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* SQL solution */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table Merged_sql as&lt;BR /&gt;
select coalesce(A.TEXT,B.TEXT,"") AS Text&lt;BR /&gt;
     , coalesce(a.Num,B.Num) as Num&lt;BR /&gt;
     , DS1&lt;BR /&gt;
     , DS2&lt;BR /&gt;
   from ds1 as a&lt;BR /&gt;
     full JOIN &lt;BR /&gt;
   ds2 as b&lt;BR /&gt;
   on a.Text=b.Text and a.Num=b.num&lt;BR /&gt;
   ;&lt;BR /&gt;
quit;&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
&lt;BR /&gt;
You can produce the same results with the following data step code &amp;amp; concatenating variables:&lt;BR /&gt;
&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
/*Data Step Solution*/&lt;BR /&gt;
data DS1a;&lt;BR /&gt;
   set DS1;&lt;BR /&gt;
   _joinvar=CATX(Text,Num);&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=DS1a;&lt;BR /&gt;
   by _joinvar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data DS2a;&lt;BR /&gt;
   set DS2;&lt;BR /&gt;
   _joinvar=CATX(Text,Num);&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=DS2a;&lt;BR /&gt;
   by _joinvar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data Merged_data_step;&lt;BR /&gt;
   merge DS1a &lt;BR /&gt;
         DS2a ;&lt;BR /&gt;
   by _joinvar;&lt;BR /&gt;
   drop _joinvar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=merged_data_step;&lt;BR /&gt;
   by Text Num;&lt;BR /&gt;
run;&lt;BR /&gt;
**********************************************************************;&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps!</description>
      <pubDate>Fri, 29 Apr 2011 02:08:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-variable-can-i-then-reverse-the-process/m-p/59498#M12898</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-04-29T02:08:57Z</dc:date>
    </item>
  </channel>
</rss>

