<?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: Transpose then merge  the two data sets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420319#M12883</link>
    <description>&lt;P&gt;You might describe what you are attempting to accomplish.&lt;/P&gt;
&lt;P&gt;Combining two data sets has many approaches depending on what the desired result may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully your result is small enough that you could post a third data set showing what the result should look like and describe the purpose.&lt;/P&gt;
&lt;P&gt;Such as should anything special be done with records with a hospital date but not and offense date?&lt;/P&gt;
&lt;P&gt;Offense date without hospital date? What about a hospital date between multiple offenses?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since it appears that you may be wanting to compare multiple values of offense and admin dates then you likely want one array to hold each of those. And since it would not make sense to have a single flag to hold all of the comparisons you likely need another array to hold the flags. But to make a more concrete example we really should see what the full set of comparison results would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2017 00:10:09 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-12-12T00:10:09Z</dc:date>
    <item>
      <title>Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420313#M12881</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data offenders;
   input  id   offence_DATE mmddyy10. sex$;
   format offence_DATE  mmddyy10.;
   datalines;
1 05/23/05  M 
1 08/01/09  M
2 04/18/01  F
2 06/10/12  F
3 01/01/11  M
;
run;


proc transpose data=offenders out=offenders1 (drop=_name_ _label_) prefix=offence_DATE;
 by id;
 var offence_DATE;
run; 
 


data HOSPITAL;
   input  id   ADMIT_date mmddyy10. ;
   format ADMIT_date mmddyy10.;
   datalines;
1 10/21/03      
1 06/29/05      
1 02/03/07 
1 09/21/08
1 08/17/09         
3 12/31/10      
3 01/02/13      
;
run;

proc transpose data=HOSPITAL out=HOSPITAL1 (drop=_name_ _label_) prefix=ADMIT_date;
 by id;
 var ADMIT_date;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried the following code, but&amp;nbsp; it doesn't work because I have a&amp;nbsp;multiple admit_date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; offenders1 HOSPITAL1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;where i=1 to end(admit_date);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; id;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; offence_DATE1 &amp;lt; ADMIT_date_i&amp;nbsp;&amp;nbsp;&amp;lt; offence_DATE2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; flag_admit=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; flag_admit=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The result will be one row for each id such as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp; offence_date1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; offence_date2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; admit_date1&amp;nbsp; admit_date2&amp;nbsp;&amp;nbsp; admit_date3...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Could you please suggest for me the best method for doing it.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 23:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420313#M12881</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-11T23:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420318#M12882</link>
      <description>&lt;P&gt;May i ask what does this&amp;nbsp; &lt;FONT color="#FF0000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#FF0000"&gt;where i=1 to end(admit_date);&lt;/FONT&gt; statement accomplish?&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;offenders1 HOSPITAL1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;where i=1 to end(admit_date);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;id;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;offence_DATE1 &amp;lt; ADMIT_date_i&amp;nbsp;&amp;nbsp;&amp;lt; offence_DATE2&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;flag_admit=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;flag_admit=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The result will be one row for each id such as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp; offence_date1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; offence_date2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; admit_date1&amp;nbsp; admit_date2&amp;nbsp;&amp;nbsp; admit_date3...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 23:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420318#M12882</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-11T23:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420319#M12883</link>
      <description>&lt;P&gt;You might describe what you are attempting to accomplish.&lt;/P&gt;
&lt;P&gt;Combining two data sets has many approaches depending on what the desired result may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully your result is small enough that you could post a third data set showing what the result should look like and describe the purpose.&lt;/P&gt;
&lt;P&gt;Such as should anything special be done with records with a hospital date but not and offense date?&lt;/P&gt;
&lt;P&gt;Offense date without hospital date? What about a hospital date between multiple offenses?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since it appears that you may be wanting to compare multiple values of offense and admin dates then you likely want one array to hold each of those. And since it would not make sense to have a single flag to hold all of the comparisons you likely need another array to hold the flags. But to make a more concrete example we really should see what the full set of comparison results would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 00:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420319#M12883</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-12T00:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420330#M12884</link>
      <description>&lt;P&gt;I am also quite mystified as to what you're aiming to achieve with the statement:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;where i=1 to end(admit_date);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable i doesn't appear in either of your input datasets.&amp;nbsp; My guess is you're trying to analyse the correspondence between offence_date and offence_date using array processing, but don't have an array statement.&amp;nbsp; In any case, array are not good at handling highly variable data (you need to define a fixed number of array elements in the datastep).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a good idea when asking for technical assistance in a forum like this, to step back and describe your problem in business terms rather than in technical details of the approach you're first attempting.&amp;nbsp; This allows others to offer solutions that may be better able to solve your underlying problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&amp;nbsp;&lt;SPAN&gt;you are trying to analyse the correspondence between offence_date and offence_date, then I'd suggest renaming, or duplicating the date variables (to event_date ?), merging by &lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;id event_date&lt;/FONT&gt;&lt;/STRONG&gt;, and maybe using lag functions to assist in identifying the correspondence between offence and hospital admission.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 00:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420330#M12884</guid>
      <dc:creator>DaveBirch</dc:creator>
      <dc:date>2017-12-12T00:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420331#M12885</link>
      <description>&lt;P&gt;sorry, but I'm trying to make as loop&lt;/P&gt;&lt;P&gt;after transpose the data from multiple row for each id to multiple column (one row) &amp;nbsp;for each id.&lt;/P&gt;&lt;P&gt;I have such as ADMIT_date1&amp;nbsp; ADMIT_date2&amp;nbsp; ADMIT_date3&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;I would like to know if the offender has&amp;nbsp; any admission to the hospital between the first offence and the second offence.&lt;/P&gt;&lt;P&gt;if YES, when ? how many times ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 00:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420331#M12885</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-12T00:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420332#M12886</link>
      <description>&lt;P&gt;Could you please show me how I can do it.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 00:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420332#M12886</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-12T00:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420337#M12887</link>
      <description>&lt;P&gt;Please give&lt;STRONG&gt; us(the community-you included)&lt;/STRONG&gt; a sample data set of your input and a sample data set of your wanted output. We can help you with the code you may require&lt;/P&gt;&lt;P&gt;PS give a brief description of the logic for us to implement&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 01:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420337#M12887</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-12T01:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420346#M12888</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data offenders;
   input  id   offence_DATE mmddyy10. sex$;
   format offence_DATE  mmddyy10.;
   datalines;
1 05/23/05  M 
1 08/01/09  M
2 04/18/01  F
2 06/10/12  F
3 01/01/11  M
;
run;


proc transpose data=offenders out=offenders1 (drop=_name_ _label_) prefix=offence_DATE;
 by id;
 var offence_DATE;
run; 
 


data HOSPITAL;
   input  id   ADMIT_date mmddyy10. ;
   format ADMIT_date mmddyy10.;
   datalines;
1 10/21/03      
1 06/29/05      
1 02/03/07 
1 12/28/09         
3 12/31/10      
3 01/02/13      
;
run;

proc transpose data=HOSPITAL out=HOSPITAL1 (drop=_name_ _label_) prefix=ADMIT_date;
 by id;
 var ADMIT_date;
run; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the result shop be look like as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp; offence_DATE1&amp;nbsp;&amp;nbsp; offence_DATE2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ADMIT_date1&amp;nbsp;&amp;nbsp;&amp;nbsp;ADMIT_date2&amp;nbsp;&amp;nbsp;&amp;nbsp;ADMIT_date3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; contact between offences&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/23/05&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 08/01/09&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10/21/03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/29/05&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12/28/09&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/18/01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/10/11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;no&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01/01/11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12/31/10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01/02/13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*** # means the count number of admission to the hospital between the two offences if the offender has two or after the first offence when the offender didn't have the second offence*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 02:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420346#M12888</guid>
      <dc:creator>elias_2020</dc:creator>
      <dc:date>2017-12-12T02:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420349#M12889</link>
      <description>&lt;P&gt;You could try something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=offenders;&lt;BR /&gt;&amp;nbsp; by id offence_date;&lt;BR /&gt;run;&lt;BR /&gt;data offenders1;&lt;BR /&gt;&amp;nbsp; set offenders; &lt;BR /&gt;&amp;nbsp; by id offence_date;&lt;BR /&gt;&amp;nbsp; prev_offence_date = lag(offence_date);&lt;BR /&gt;&amp;nbsp; if first.id then delete;&lt;BR /&gt;&amp;nbsp; /* assuming only interested in offenders with multiple offences */&lt;BR /&gt;&amp;nbsp; /* otherwise we may need the following line and others */&lt;BR /&gt;&amp;nbsp; /*if first.id then prev_offence_date = .;*/&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=hospital;&lt;BR /&gt;&amp;nbsp; by id admit_date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* SQL handles M:N instances better than data step MERGE */&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp; create table want1 as&lt;BR /&gt;&amp;nbsp; select id, prev_offence_date, offence_date,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;admit_date, sex&lt;BR /&gt;&amp;nbsp; from offenders1 t1&lt;BR /&gt;&amp;nbsp; left join hospital t2 &lt;BR /&gt;&amp;nbsp; on (t1.id eq t2.id)&lt;BR /&gt;&amp;nbsp; where (t1.prev_offence_date le t2.admit_date lt t1.offence_date)&lt;BR /&gt;&amp;nbsp; order by t1.id, t1.offence_date, t2.admit_date;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You now have a dataset with a row for every hospital admission that occurs "between" offences for offenders.&amp;nbsp; This is in many ways easier to analyse (and more flexible) than a more "flattened" structure.&amp;nbsp; If you do desire to flatten it, there are many business issues still to be resolved to determine the best approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 03:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420349#M12889</guid>
      <dc:creator>DaveBirch</dc:creator>
      <dc:date>2017-12-12T03:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then merge  the two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420381#M12890</link>
      <description>&lt;P&gt;It is probably going to be easier to combine the files in their original format instead of the transposed format. Perhaps something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  row+1;
  length id date_no 8;
  set offenders(in=in1 rename=(offence_date=DATE))
      hospital (in=in2 rename=(admit_date=DATE))
  ;
  by id date ;
  if in1 then offence_date=date ;
  if in2 then admit_date=date ;
  date_no + first.date;
  if first.id then date_no=1 ;
  format date admit_date offence_date yymmdd10. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 453px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17156i6AF5CFD1731EEF44/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So what does your new FLAG variable represent?&amp;nbsp; Which rows do you want to FLAG for this sample data?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 07:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transpose-then-merge-the-two-data-sets/m-p/420381#M12890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-12T07:17:54Z</dc:date>
    </item>
  </channel>
</rss>

