<?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: Transposing a dataset by criteria in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499889#M242</link>
    <description>&lt;P&gt;I think I understand the intent here.&amp;nbsp; To begin, make sure the data is properly sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by House_ID DOB;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are getting pairs of observations, a DATA Step (with some renaming) would be an appropriate tool:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by House_ID;&lt;/P&gt;
&lt;P&gt;if first.House_ID then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; id_0 = id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;dob_0 = dob;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if last.House_ID then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;id_1 = id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;dob_1 = dob;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain id_0 dob_0;&lt;/P&gt;
&lt;P&gt;drop id dob;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Sep 2018 13:26:51 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-09-28T13:26:51Z</dc:date>
    <item>
      <title>Transposing a dataset by criteria</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499827#M234</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone think of a way to go from A to B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would like to carry out a transpose but would be transposed by the oldest person in the house.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Have


ID	House_id	DOB
024978P	602A7C469ADDA38E96A	01-Aug-84
0565758T	602A7C469ADDA38E96A	01-Jan-05
09363467P	602A7C469ADDA38E96A	01-Feb-06
048837O	602A7C469ADDA38E96A	01-Mar-12
035485W	9D2C6FCAB9F90027A	01-Jun-48
0614701F	F2D053348CF80DE494D650	01-Mar-45
08088430X	F2D053348CF80DE494D650	01-Nov-51

WANT

ID	ID_1	DOB	DOB_1	House_ID
024978P	0565758T	01-Aug-84	01-Jan-05	602A7C469ADDA38E96A
024978P	09363467P	01-Aug-84	01-Feb-06	602A7C469ADDA38E96A
048837O		01-Mar-12		602A7C469ADDA38E96A
0614701F	08088430X	01-Mar-45	01-Nov-51	F2D053348CF80DE494D650

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 10:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499827#M234</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2018-09-28T10:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a dataset by criteria</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499840#M236</link>
      <description>&lt;P&gt;Use arrays, you can check the maximum iterations before, for my code I just assumed 1:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by house_id;
  array id_{1} $200;
  array dob_{1} $200;
  if not(first.house_id) then do;
    id_{1}=id;
    dob_{1}=dob;
  end;
  if last.house_id then output;
run;&lt;/PRE&gt;
&lt;P&gt;Of course you will likely have a lot more than 1, so you would need to calculate how many and not hardcode in.&amp;nbsp; If you do only have one, then just retain the two extra variables.&amp;nbsp; You could also just do two proc transposes and merge them back on.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 11:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499840#M236</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-28T11:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a dataset by criteria</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499889#M242</link>
      <description>&lt;P&gt;I think I understand the intent here.&amp;nbsp; To begin, make sure the data is properly sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by House_ID DOB;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are getting pairs of observations, a DATA Step (with some renaming) would be an appropriate tool:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by House_ID;&lt;/P&gt;
&lt;P&gt;if first.House_ID then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; id_0 = id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;dob_0 = dob;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if last.House_ID then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;id_1 = id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;dob_1 = dob;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain id_0 dob_0;&lt;/P&gt;
&lt;P&gt;drop id dob;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 13:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transposing-a-dataset-by-criteria/m-p/499889#M242</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-28T13:26:51Z</dc:date>
    </item>
  </channel>
</rss>

