<?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: Proc sql macro in loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823430#M325122</link>
    <description>Why not use PROC TRANSPOSE instead?</description>
    <pubDate>Thu, 14 Jul 2022 21:41:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-07-14T21:41:01Z</dc:date>
    <item>
      <title>Proc sql macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823429#M325121</link>
      <description>&lt;P&gt;hello--&lt;/P&gt;&lt;P&gt;I have a wide dataset (100 columns) that I would like to transpose by patientID to long. I have 30 columns that all have the same prefix diag_1,diag_2, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to write macro within a proc sql loop that would select union through each of the diag_ variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tia!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 21:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823429#M325121</guid>
      <dc:creator>nyy2</dc:creator>
      <dc:date>2022-07-14T21:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823430#M325122</link>
      <description>Why not use PROC TRANSPOSE instead?</description>
      <pubDate>Thu, 14 Jul 2022 21:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823430#M325122</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-14T21:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823438#M325124</link>
      <description>&lt;P&gt;What are the other 69 columns? Or do you not want them included in the long set?&lt;/P&gt;
&lt;P&gt;Does PatientId repeat in the data, such as on different dates or different facilities? Is the date/facility/other information to be in the result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that you have a date along with the patient Id this is how I would start this:&lt;/P&gt;
&lt;PRE&gt;Proc sort data=have;
   by PatientId Visitdate;
run;

Proc transpose data=have out=long;
   by patientid visitdate;
   var diag_: ;
run;&lt;/PRE&gt;
&lt;P&gt;You want to include enough variables in the BY statement in both Proc Sort and transpose to uniquely identify the source record. The Diag_: is a list that tells SAS to use all the variables whose names start with Diag_ . If there are some that are different than your numbered variables that you would not want then use the list Diag_1 - Diag_30 (assumes they are sequentially numbered).&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 22:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823438#M325124</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-14T22:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823439#M325125</link>
      <description>&lt;P&gt;Basically there's a few ways to transpose data and SQL is the last option in the list of options by preference because you have to manually do everything. Using a data step and array, proc transpose are the best options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 23:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-macro-in-loop/m-p/823439#M325125</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-14T23:06:57Z</dc:date>
    </item>
  </channel>
</rss>

