<?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 Merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503446#M134520</link>
    <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;I did order freq to find out if there are any duplicate ids and there are no duplicate ids&lt;/P&gt;&lt;P&gt;proc freq data=STDTELMT.Treat18_TRANSPOSED order=freq;&lt;BR /&gt;table event_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;the visit data set has 2105 observations, treat data set has 752 observation with common variable event_id. I sorted both data set by event_id and tried to merge and they are not merged by event id instead treat data set is stacked on top of visit data set. Could you please tell me what did do wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Sorting visit data by event_id:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sort data=STDTELMT.VISIT18_MERGED;&lt;BR /&gt;by event_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/&lt;U&gt;*SORTING TREATMENT DATA BEFORE TRANSPOSING BY EVENT_ID*/&lt;/U&gt;&lt;BR /&gt;PROC SORT DATA=RX_MERGED;;&lt;BR /&gt;BY EVENT_ID;&lt;BR /&gt;RUN;&lt;BR /&gt;/*REMOVING DUPLICATES*/&lt;BR /&gt;data STDTELMT.TREAT_COUNT;&lt;BR /&gt;set RX_MERGED;&lt;BR /&gt;by event_id;&lt;BR /&gt;t_f=first.event_id;&lt;BR /&gt;t_l=last.event_id;&lt;BR /&gt;if t_f=1;&lt;BR /&gt;run;&lt;BR /&gt;/*TRANSPOSING TREATMENT DATSET*/&lt;BR /&gt;proc transpose data=STDTELMT.TREAT_COUNT out=STDTELMT.Treat18_TRANSPOSED;&lt;BR /&gt;by EVENT_ID ;&lt;BR /&gt;ID RX;&lt;BR /&gt;var RX;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;U&gt;merging two (visit and treat) data sets&lt;/U&gt;&lt;/P&gt;&lt;P&gt;DATA STDTELMT.MERGED ;&lt;BR /&gt;MERGE STDTELMT.VISIT18_MERGED STDTELMT.Treat18_TRANSPOSED;&lt;BR /&gt;by event_id;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;U&gt;the log says :&lt;/U&gt;&lt;/P&gt;&lt;P&gt;NOTE: There were 2105 observations read from the data set STDTELMT.VISIT18_MERGED.&lt;BR /&gt;NOTE: There were 752 observations read from the data set STDTELMT.TREAT18_TRANSPOSED.&lt;BR /&gt;NOTE: The data set STDTELMT.MERGED has 2857 observations and 41 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.13 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
    <pubDate>Thu, 11 Oct 2018 15:45:15 GMT</pubDate>
    <dc:creator>Dhana18</dc:creator>
    <dc:date>2018-10-11T15:45:15Z</dc:date>
    <item>
      <title>Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503446#M134520</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;I did order freq to find out if there are any duplicate ids and there are no duplicate ids&lt;/P&gt;&lt;P&gt;proc freq data=STDTELMT.Treat18_TRANSPOSED order=freq;&lt;BR /&gt;table event_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;the visit data set has 2105 observations, treat data set has 752 observation with common variable event_id. I sorted both data set by event_id and tried to merge and they are not merged by event id instead treat data set is stacked on top of visit data set. Could you please tell me what did do wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Sorting visit data by event_id:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sort data=STDTELMT.VISIT18_MERGED;&lt;BR /&gt;by event_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/&lt;U&gt;*SORTING TREATMENT DATA BEFORE TRANSPOSING BY EVENT_ID*/&lt;/U&gt;&lt;BR /&gt;PROC SORT DATA=RX_MERGED;;&lt;BR /&gt;BY EVENT_ID;&lt;BR /&gt;RUN;&lt;BR /&gt;/*REMOVING DUPLICATES*/&lt;BR /&gt;data STDTELMT.TREAT_COUNT;&lt;BR /&gt;set RX_MERGED;&lt;BR /&gt;by event_id;&lt;BR /&gt;t_f=first.event_id;&lt;BR /&gt;t_l=last.event_id;&lt;BR /&gt;if t_f=1;&lt;BR /&gt;run;&lt;BR /&gt;/*TRANSPOSING TREATMENT DATSET*/&lt;BR /&gt;proc transpose data=STDTELMT.TREAT_COUNT out=STDTELMT.Treat18_TRANSPOSED;&lt;BR /&gt;by EVENT_ID ;&lt;BR /&gt;ID RX;&lt;BR /&gt;var RX;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;U&gt;merging two (visit and treat) data sets&lt;/U&gt;&lt;/P&gt;&lt;P&gt;DATA STDTELMT.MERGED ;&lt;BR /&gt;MERGE STDTELMT.VISIT18_MERGED STDTELMT.Treat18_TRANSPOSED;&lt;BR /&gt;by event_id;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;U&gt;the log says :&lt;/U&gt;&lt;/P&gt;&lt;P&gt;NOTE: There were 2105 observations read from the data set STDTELMT.VISIT18_MERGED.&lt;BR /&gt;NOTE: There were 752 observations read from the data set STDTELMT.TREAT18_TRANSPOSED.&lt;BR /&gt;NOTE: The data set STDTELMT.MERGED has 2857 observations and 41 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.13 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 15:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503446#M134520</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2018-10-11T15:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503480#M134540</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212762"&gt;@Dhana18&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;I did order freq to find out if there are any duplicate ids and there are no duplicate ids&lt;/P&gt;
&lt;P&gt;proc freq data=STDTELMT.Treat18_TRANSPOSED order=freq;&lt;BR /&gt;table event_id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA STDTELMT.MERGED ;&lt;BR /&gt;MERGE STDTELMT.VISIT18_MERGED STDTELMT.Treat18_TRANSPOSED;&lt;BR /&gt;by event_id;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;the log says :&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;NOTE: There were 2105 observations read from the data set STDTELMT.VISIT18_MERGED.&lt;BR /&gt;NOTE: There were 752 observations read from the data set STDTELMT.TREAT18_TRANSPOSED.&lt;BR /&gt;NOTE: The data set STDTELMT.MERGED has 2857 observations and 41 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.13 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since 2105 + 752 = 2857 that indicates that there are no exact matches at all between the values of the EVENT_ID variable in STDTELMT.VISIT18_MERGED and STDTELMT.TREAT18_TRANSPOSED&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to look very closely at the values of your variable.&lt;/P&gt;
&lt;P&gt;If the variable is character look for leading spaces or differences in capitalization between values you think match. Also there might be other non-printable characters trailing. Check the assigned length of the values to see if they match.&lt;/P&gt;
&lt;PRE&gt;data example;
   x='abc&amp;nbsp;';
   y=length(x);
   put y=;
run;&lt;/PRE&gt;
&lt;P&gt;In the above code the character after the c in 'abc&amp;nbsp;' is not a blank but the ASCII null character. So while the output might look like X is 3 characters it actually has 4 and would not match a value of 'abc' or 'abc ' (with a space) for merging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable is numeric you might accidentally have decimal portions of the value in one or both sets that don't match.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 17:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503480#M134540</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-11T17:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503524#M134560</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212762"&gt;@Dhana18&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ballardw&lt;/STRONG&gt;'s advice is very good (as always). If I were to implement it, I would proceed as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, print unformatted values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=stdtelmt.treat18_transposed(firstobs=752);
format event_id;
var event_id;
run;

proc print data=stdtelmt.visit18_merged(obs=1);
format event_id;
var event_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both steps print only one EVENT_ID value. According to your problem description ("&lt;SPAN&gt;treat data set is stacked on top of visit data set"), the first of the two printed values must be lexicographically smaller than the second (assuming &lt;EM&gt;character&lt;/EM&gt; variables, otherwise: &lt;EM&gt;numerically&lt;/EM&gt; smaller) -- contrary to your expectation of matching values in VISIT18_MERGED for each EVENT_ID from TREAT18_TRANSPOSED.&amp;nbsp;&lt;/SPAN&gt;If this does not &lt;EM&gt;seem&lt;/EM&gt; to be the case, please repeat the above two steps with an extended FORMAT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;format event_id &lt;FONT color="#FF0000"&gt;$hex30.&lt;/FONT&gt;;&lt;/PRE&gt;
&lt;P&gt;(again, assuming character variables EVENT_ID, of length &amp;lt;=15; if they are numeric, please use &lt;FONT face="courier new,courier"&gt;format event_id &lt;FONT color="#FF0000"&gt;hex16.&lt;/FONT&gt;;&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;and post the results.&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;
&lt;P&gt;@ Super Users: It looks like this thread is actually a continuation of &lt;A href="https://communities.sas.com/t5/SAS-Programming/merging/m-p/502914" target="_blank"&gt;this one&lt;/A&gt;&amp;nbsp;and the two should be merged.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 18:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/503524#M134560</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-11T18:43:03Z</dc:date>
    </item>
  </channel>
</rss>

