<?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 proc sql for vertical to horizontal data set conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478502#M286364</link>
    <description>&lt;P&gt;Dear SAS users,&lt;/P&gt;&lt;P&gt;I do have a large data set with multiple patients (Pt_ID). There can be multiple entries for a single patient (each entry is recorded by the same Pt_ID). For each Pt_ID, same specimen is collected at different times (datetime variable - Collection_Date). However, for a given Collection_Date for a given Pt_ID, sometimes 5 tests (variable CULTURE_TYPE) are run and for the same Pt_ID for the next collection_time, there may be 3 tests (CULTURE_TYPE) done.&amp;nbsp; CULTURE_TYPE are of 7 types (Type1, Type2, Type3...Type7).&amp;nbsp; I want to rearrange the data set&amp;nbsp; horizontally from vertical format, so that for each Pt_ID, for a unique Collection_Date, I will have&amp;nbsp;CULTURE_TYPE1,&amp;nbsp;CULTURE_TYPE2,&amp;nbsp;CULTURE_TYPE3...etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also another twist for this data set, for a given Type of CULTURE_TYPE (Type1 or Type2 or..Type7), there may be one bacteria that is isolated or two bacteria isolated (variable Organism). For example, If there are two organisms identified for a Type1, they have same Accession_No. Each Type has different Accession_no's. For example Type1 will have a unique Accession_no, Type2 will have another Accession_no, Type3....etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result for each organism will be (Yes/ NO = Y/N), captured as a separate variable (Result_Uc).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically I need this data set to be in horizontal form for a unique Collection_Date and Culture_Type and Organism transposed horizontally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see the attached excel sheet for the data set and variables. I highlighted duplicate accession_no's in RED.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for all the help!&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jul 2018 21:57:32 GMT</pubDate>
    <dc:creator>sms1891</dc:creator>
    <dc:date>2018-07-16T21:57:32Z</dc:date>
    <item>
      <title>proc sql for vertical to horizontal data set conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478502#M286364</link>
      <description>&lt;P&gt;Dear SAS users,&lt;/P&gt;&lt;P&gt;I do have a large data set with multiple patients (Pt_ID). There can be multiple entries for a single patient (each entry is recorded by the same Pt_ID). For each Pt_ID, same specimen is collected at different times (datetime variable - Collection_Date). However, for a given Collection_Date for a given Pt_ID, sometimes 5 tests (variable CULTURE_TYPE) are run and for the same Pt_ID for the next collection_time, there may be 3 tests (CULTURE_TYPE) done.&amp;nbsp; CULTURE_TYPE are of 7 types (Type1, Type2, Type3...Type7).&amp;nbsp; I want to rearrange the data set&amp;nbsp; horizontally from vertical format, so that for each Pt_ID, for a unique Collection_Date, I will have&amp;nbsp;CULTURE_TYPE1,&amp;nbsp;CULTURE_TYPE2,&amp;nbsp;CULTURE_TYPE3...etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also another twist for this data set, for a given Type of CULTURE_TYPE (Type1 or Type2 or..Type7), there may be one bacteria that is isolated or two bacteria isolated (variable Organism). For example, If there are two organisms identified for a Type1, they have same Accession_No. Each Type has different Accession_no's. For example Type1 will have a unique Accession_no, Type2 will have another Accession_no, Type3....etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result for each organism will be (Yes/ NO = Y/N), captured as a separate variable (Result_Uc).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically I need this data set to be in horizontal form for a unique Collection_Date and Culture_Type and Organism transposed horizontally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see the attached excel sheet for the data set and variables. I highlighted duplicate accession_no's in RED.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for all the help!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 21:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478502#M286364</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2018-07-16T21:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql for vertical to horizontal data set conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478503#M286365</link>
      <description>&lt;P&gt;First, I think requiring PROC SQL is the wrong thing here, and so I will make no attempt to find an SQL solution. Use PROC TRANSPOSE with a BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, I think leaving the data in the format it is in and not transposing it will make the analysis easier. Of course, I don't know what type of analysis you plan to do, but rarely is a wide format superior to a long format.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478503#M286365</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-16T22:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql for vertical to horizontal data set conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478504#M286366</link>
      <description>&lt;P&gt;Your topic title seems to imply that you only want an SQL solution. Is that actually case? It may be possible but I'm afraid that the code could get voluminous.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell use exactly what you will be doing that requires the wide format you describe? It may be easier to leave the data in the current form a use a slightly different process than currently envisioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you really should provide what you expect for the result as a table as I am not sure I can get a clear grasp on CULTURE_TYPE1,&amp;nbsp;CULTURE_TYPE2,&amp;nbsp;CULTURE_TYPE3 (how many would there be??? another issue with "wide" data) and then adding an unknown number of Result_Uc varaibles as well.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 22:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-for-vertical-to-horizontal-data-set-conversion/m-p/478504#M286366</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-16T22:10:40Z</dc:date>
    </item>
  </channel>
</rss>

