<?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 data with dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569792#M160605</link>
    <description>&lt;P&gt;There are a few error in your test data. However, you can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  input patientid  date2 : mmddyy10. (x1-x7)(:$);
  format date2  mmddyy10.;
datalines;
4 5/5/2009    Y . . . . . .
4 5/5/2009    . Y . . . . . .
4 5/5/2009     . . Y . . . .
4 5/6/2009    Y . . . . . .
4 5/6/2009    . Y . . . . . .
4 5/6/2009     . . Y . . . .
4 5/6/2009    . . . y . . . 
4 5/6/2009    . . . . y . . 
4 5/6/2009     . . . . . y . 
5 5/5/2009    Y . . . . . .
5 5/5/2009    . Y . . . . . .
5 5/5/2009     . . Y . . . .
;

data want;
    update b(obs=0) b;
    by patientid date2;
    if last.date2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Jun 2019 13:46:35 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-06-28T13:46:35Z</dc:date>
    <item>
      <title>transpose data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569782#M160602</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  input patientid  date2 : mmddyy10. x1 x2 x3 x4 x5 x6 x7;
  format date2  mmddyy10.;
datalines;
4 5/5/2009    Y . . . . . .
4 5/5/2009    . Y . . . . . .
4/5/5/2009     . . Y . . . .
4 5/6/2009    Y . . . . . .
4 5/6/2009    . Y . . . . . .
4/5/6/2009     . . Y . . . .
4 5/6/2009    . . . y . . . 
4 5/6/2009    . . . . y . . 
4/5/6/2009     . . . . . y . 
5 5/5/2009    Y . . . . . .
5 5/5/2009    . Y . . . . . .
5/5/5/2009     . . Y . . . .;
run; 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the following data entered in a way for which observations happening in the same day are entered into columns rather than the same row. I want to transpose it to the following format&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id date2        x1 x2 x3 x4 x5 x6 x7 
4 5/5/2009    Y  Y  Y    .    .    .    . 
4/5/6/2009    Y  Y  Y   Y   Y   Y   .  
5 5/5/2009    Y  Y  Y   .    .    .    . 

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 13:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569782#M160602</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2019-06-28T13:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569792#M160605</link>
      <description>&lt;P&gt;There are a few error in your test data. However, you can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  input patientid  date2 : mmddyy10. (x1-x7)(:$);
  format date2  mmddyy10.;
datalines;
4 5/5/2009    Y . . . . . .
4 5/5/2009    . Y . . . . . .
4 5/5/2009     . . Y . . . .
4 5/6/2009    Y . . . . . .
4 5/6/2009    . Y . . . . . .
4 5/6/2009     . . Y . . . .
4 5/6/2009    . . . y . . . 
4 5/6/2009    . . . . y . . 
4 5/6/2009     . . . . . y . 
5 5/5/2009    Y . . . . . .
5 5/5/2009    . Y . . . . . .
5 5/5/2009     . . Y . . . .
;

data want;
    update b(obs=0) b;
    by patientid date2;
    if last.date2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 13:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569792#M160605</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-28T13:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569814#M160614</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;There was an issue with the data as there was forward slashes between patientid and date2.&lt;/P&gt;&lt;P&gt;I removed them and replaced Y with numbers to show that it is working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code, if you want to try. Please let me know if this is what you wanted. I might have read the requirements wrong. After the code is the output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
	input patientid date2 : mmddyy10. x1 x2 x3 x4 x5 x6 x7;
	format date2 mmddyy10.;
	datalines;
4 5/5/2009    1 . . . . . .
4 5/5/2009    . 2 . . . . . .
4 5/5/2009     . . 3 . . . .
4 5/6/2009    4 . . . . . .
4 5/6/2009    . 5 . . . . . .
4 5/6/2009     . . 6 . . . .
4 5/6/2009    . . . 7 . . . 
4 5/6/2009    . . . . 8 . . 
4 5/6/2009     . . . . . 9 . 
5 5/5/2009    1 . . . . . .
5 5/5/2009    . 2 . . . . . .
5/5/5/2009     . . 3 . . . .;
run;

PROC REPORT data=b;
	COLUMNS patientid date2 (x1 x2 x3 x4 x5 x6 x7);
	DEFINE patientid / GROUP;
	DEFINE date2 / GROUP;
	DEFINE x1 / ACROSS SUM;
	DEFINE x2 / ACROSS SUM;
	DEFINE x3 / ACROSS SUM;
	DEFINE x4 / ACROSS SUM;
	DEFINE x5 / ACROSS SUM;
	DEFINE x6 / ACROSS SUM;
	DEFINE x7 / ACROSS SUM;
RUN;&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;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output" style="width: 317px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30622i6BD967746030C061/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output_01.png" alt="Output" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Output&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 14:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569814#M160614</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-06-28T14:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569817#M160615</link>
      <description>Elegant</description>
      <pubDate>Fri, 28 Jun 2019 14:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569817#M160615</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-06-28T14:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569823#M160616</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 14:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-with-dates/m-p/569823#M160616</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2019-06-28T14:08:42Z</dc:date>
    </item>
  </channel>
</rss>

