<?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: How do I place long data (with some repeated measures) into defined wide time periods? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286109#M59471</link>
    <description>&lt;P&gt;The code you provided definitely got me closer to where I want to be. See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;StudyID&amp;nbsp;StartDate EndDate ScoreDate R_Score M_Score S_Score P_Score count&lt;/P&gt;&lt;P class="p1"&gt;01&amp;nbsp;2007-01-01 2007-01-30 01/11/2007 1 3 3 3 1&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 02/01/2007 1 3 3 3 2&lt;/P&gt;&lt;P class="p1"&gt;01&amp;nbsp;2007-01-31 2008-04-30 05/17/2007 1 3 3 3 3&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 10/26/2007 1 4 4 3 4&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 11/06/2007 1 5 5 3 5&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 11/07/2007 1 3 3 3 6&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 11/21/2007 1 3 3 3 7&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 12/31/2007 1 3 3 3 8&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 03/18/2008 1 3 3 3 9&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 06/04/2012 2 3 3 2 1&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 08/08/2012 2 3 3 2 2&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 09/27/2012 2 3 3 2 3&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 11/26/2012 2 3 3 2 4&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 01/29/2013 2 3 3 2 5&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 03/21/2013 2 3 3 2 6&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 04/05/2013 2 3 3 2 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I think I was ultimately thinking of Option #2 (&lt;SPAN&gt;the same arbitrarily large number of columns, many of which will be empty)&lt;/SPAN&gt;. Do you have recommendations for next steps on how to get there from here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jul 2016 12:56:21 GMT</pubDate>
    <dc:creator>Kels123</dc:creator>
    <dc:date>2016-07-21T12:56:21Z</dc:date>
    <item>
      <title>How do I place long data (with some repeated measures) into defined wide time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286001#M59448</link>
      <description>&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I have long, repeated data for my participants (sample data on first two participants shown below):&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;StudyID ScoreDate R_Score M_Score S_Score P_Score count&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 01/11/2007 1 3 3 3 1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 02/01/2007 1 3 3 3 2&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 05/17/2007 1 3 3 3 3&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 10/26/2007 1 4 4 3 4&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 11/06/2007 1 5 5 3 5&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 11/07/2007 1 3 3 3 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 11/21/2007 1 3 3 3 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 12/31/2007 1 3 3 3 8&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 03/18/2008 1 3 3 3 9&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 06/04/2012 2 3 3 2 1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 08/08/2012 2 3 3 2 2&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 09/27/2012 2 3 3 2 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 11/26/2012 2 3 3 2 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 01/29/2013 2 3 3 2 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 03/21/2013 2 3 3 2 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 04/05/2013 2 3 3 2 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I also have a second database of time periods of interest, specified by a start and end date, as follows (sample data for the first two participants):&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;StudyID StartDate EndDate&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 2007-01-01 2007-01-30&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 2007-01-31 2008-04-30&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0001 2008-05-01 2015-01-01&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 2007-01-01 2012-05-31&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 2012-06-01 2013-05-23&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0002 2013-05-24 2015-01-01&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I need to combine these two databases by placing the score data into the correct time periods based on whether the ScoreDate (e.g. 05/17/2007) fits into the time period (e.g. 2007-01-31 to 2008-04-30). If the ScoreDate fits into a certain period, I need to put the ScoreDate and all three corresponding scores into that period. If there are multiple ScoreDates that belong in that time period, then I need all ScoreDates and corresponding scores to be entered (in wide format) into that period (preferably with some type of indicator, e.g. ScoreDate1 R_Score1 M_Score1 S_Score1 P_Score1 and ScoreDate2 R_Score2 M_Score1 S_Score2 P_Score2, so that I know which scores were measured&amp;nbsp;on which date. I also need to be able to later compare the ScoreDate to the time period StartDate and EndDate, so I think ScoreDate needs to stay as a variable). If there are no ScoreDates for a certain period, then the period remains unchanged (with no additional variables).&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I think this could be somewhat straightforward using PROC SQL, but I am still learning how to use it and I could really use some guidance. Thank you very much.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 23:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286001#M59448</guid>
      <dc:creator>Kels123</dc:creator>
      <dc:date>2016-07-20T23:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I place long data (with some repeated measures) into defined wide time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286003#M59449</link>
      <description>&lt;P&gt;I'm not sure if I exactly understand your question, i can see it two ways and if it's one of&amp;nbsp;the ways, this code may work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
    SELECT  tbl_2.StudyID
           ,tbl_2.StartDate
           ,tbl_2.EndDate
           ,tbl_1.ScoreDate 
           ,tbl_1.R_Score 
           ,tbl_1.M_Score 
           ,tbl_1.S_Score 
           ,tbl_1.P_Score 
           ,tbl_1.count 
    FROM            tbl_2
    INNER JOIN      tbl_1
                 ON tbl_2.StudyID    = tbl_1.StudyID
                AND tbl_2.StartDate &amp;lt;= tbl_1.ScoreDate
                AND tbl_2.EndDate   &amp;gt;= tbl_1.ScoreDate;                
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if by wide you mean you want differing number of columns in the output dataset per row (or more accurately the same arbitrarily large number of columns, many of which will be empty) and only one row in the output dataset per row in tbl_2, then that is more difficult although still possible, in DBs like Oracle there are some easy ways to do this, but not in SAS via a single step that I'm aware of.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 00:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286003#M59449</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2016-07-21T00:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I place long data (with some repeated measures) into defined wide time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286022#M59453</link>
      <description>&lt;P&gt;You did not post the output yet .&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 02:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286022#M59453</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-21T02:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I place long data (with some repeated measures) into defined wide time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286109#M59471</link>
      <description>&lt;P&gt;The code you provided definitely got me closer to where I want to be. See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;StudyID&amp;nbsp;StartDate EndDate ScoreDate R_Score M_Score S_Score P_Score count&lt;/P&gt;&lt;P class="p1"&gt;01&amp;nbsp;2007-01-01 2007-01-30 01/11/2007 1 3 3 3 1&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 02/01/2007 1 3 3 3 2&lt;/P&gt;&lt;P class="p1"&gt;01&amp;nbsp;2007-01-31 2008-04-30 05/17/2007 1 3 3 3 3&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 10/26/2007 1 4 4 3 4&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 11/06/2007 1 5 5 3 5&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 11/07/2007 1 3 3 3 6&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 11/21/2007 1 3 3 3 7&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 12/31/2007 1 3 3 3 8&lt;/P&gt;&lt;P class="p1"&gt;01 2007-01-31 2008-04-30 03/18/2008 1 3 3 3 9&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 06/04/2012 2 3 3 2 1&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 08/08/2012 2 3 3 2 2&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 09/27/2012 2 3 3 2 3&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 11/26/2012 2 3 3 2 4&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 01/29/2013 2 3 3 2 5&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 03/21/2013 2 3 3 2 6&lt;/P&gt;&lt;P class="p1"&gt;02 2012-06-01 2013-05-23 04/05/2013 2 3 3 2 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I think I was ultimately thinking of Option #2 (&lt;SPAN&gt;the same arbitrarily large number of columns, many of which will be empty)&lt;/SPAN&gt;. Do you have recommendations for next steps on how to get there from here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 12:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286109#M59471</guid>
      <dc:creator>Kels123</dc:creator>
      <dc:date>2016-07-21T12:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I place long data (with some repeated measures) into defined wide time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286220#M59478</link>
      <description>&lt;P&gt;I don't have any code handy that would do that, but my first thoughts would be to take the output of the code I sent earlier and process it through a data step where you output a separate dataset for each unique value from table 1 (studyID, startDate, EndDate). &amp;nbsp;Each file would only have one variable and you would sequentially output&amp;nbsp;&lt;SPAN&gt;R_Score M_Score S_Score P_Score count to the file. &amp;nbsp;At that point you'll have X files (where X is the number of unique study periods in tbl 1). &amp;nbsp;You could then do a PROC TRANSPOSE on the file to get a single row instead of a huge number of rows. &amp;nbsp;I'm not sure about the best way to go about putting the X rows into 1 dataset at that point though. &amp;nbsp;It may be easiest to export to CSV at that point, combine the files there and then reimport into a dataset (assuming you're not ok with just a CSV as the result).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 19:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286220#M59478</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2016-07-21T19:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I place long data (with some repeated measures) into defined wide time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286346#M59494</link>
      <description>&lt;P&gt;&lt;SPAN&gt;proc transpose&amp;nbsp;&lt;/SPAN&gt;is a good idea. I think you don't even need to create X data sets, just run it directly on the output Sven111 provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose&amp;nbsp;data= &amp;nbsp;out=want ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by&amp;nbsp;&lt;SPAN&gt;StudyID&amp;nbsp;StartDate EndDate;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;id&amp;nbsp;ScoreDate;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;var&amp;nbsp;R_Score M_Score S_Score P_Score count;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...or some variant of the above. Look into the doc of proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: The above is not a perfect solution, as it will create 5 rows for each by group: one for each variable (&lt;SPAN&gt;R_Score M_Score S_Score P_Score count&lt;/SPAN&gt;). If you one to transpose the dataset only because of displaying purposes, you could first put all those 5 variables into a single character variable: vars_char=catx(' ',&lt;SPAN&gt;R_Score,M_Score,S_Score,P_Score,count) &amp;nbsp; &amp;nbsp;and do the traspose after that.&lt;BR /&gt;&lt;/SPAN&gt;If you need additional processing on the results... In that case I would not do the transose at all &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2016 09:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-place-long-data-with-some-repeated-measures-into/m-p/286346#M59494</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2016-07-22T09:32:50Z</dc:date>
    </item>
  </channel>
</rss>

