<?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 data from long to wide in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919795#M362294</link>
    <description>&lt;P&gt;Leave this data in the long format. Most SAS procedures work with data in the long format. If you want it wide because you are preparing some sort of report, please say that, and we can provide solutions that take a long data set and make a wide report.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Mar 2024 16:53:46 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-03-11T16:53:46Z</dc:date>
    <item>
      <title>Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919786#M362290</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to transpose my dataset from long to wide, but I keep getting errors due to reoccurring ID values.&lt;/P&gt;
&lt;P&gt;Context: it is survey data taken over 5-year period so there are multiple records per participant&lt;/P&gt;
&lt;P&gt;questionID: Id num for each question name&lt;/P&gt;
&lt;P&gt;QuestionName= are the question name for each question&lt;/P&gt;
&lt;P&gt;ID= unique patient identifier&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are my codes:&lt;/P&gt;
&lt;P&gt;proc sort data= data;&lt;BR /&gt;by ID QuestionName QuestionID ResponseDate ResponseTime;&lt;BR /&gt;run;&lt;BR /&gt;/*Filtering data per unique questionID by ID*/&lt;BR /&gt;data want;&lt;BR /&gt;set data;&lt;BR /&gt;by ID QuestionId;&lt;BR /&gt;if QuestionId not in (101569, 101570); /*same question but duplicate ID*/&lt;BR /&gt;if first.QuestionId;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data= want;&amp;nbsp;&lt;BR /&gt;by ID QuestionName;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;/*Transposing filtered data into wide format*/&lt;BR /&gt;proc transpose data= want = wide_data (drop=_NAME_);&lt;BR /&gt;by ID;&lt;BR /&gt;id QuestionName;&lt;BR /&gt;var Response; &lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 16:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919786#M362290</guid>
      <dc:creator>Rou</dc:creator>
      <dc:date>2024-03-11T16:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919789#M362291</link>
      <description>&lt;P&gt;If you have it multiple times per person then include another variable in the BY statement that indicates the time the data was collected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the values of the variable(s) you have in the ID statement?&amp;nbsp; Those will be used to create the variable names, so they cannot exceed 32 bytes total or they will be truncated.&amp;nbsp; Truncation could cause duplicates.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 16:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919789#M362291</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-11T16:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919795#M362294</link>
      <description>&lt;P&gt;Leave this data in the long format. Most SAS procedures work with data in the long format. If you want it wide because you are preparing some sort of report, please say that, and we can provide solutions that take a long data set and make a wide report.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 16:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919795#M362294</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-11T16:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919798#M362295</link>
      <description>&lt;P&gt;VarName exceeds the 32-byte limit, leading to a duplicate once truncated because some of the var names are not unique. How can I address this issue in SAS? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 17:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919798#M362295</guid>
      <dc:creator>Rou</dc:creator>
      <dc:date>2024-03-11T17:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919799#M362296</link>
      <description>Map the names to shorter names so that the problem goes away. &lt;BR /&gt;&lt;BR /&gt;You could leave the truncated names and add in ID labels that are unique but it's annoying.</description>
      <pubDate>Mon, 11 Mar 2024 17:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919799#M362296</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-03-11T17:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919801#M362297</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427127"&gt;@Rou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;VarName exceeds the 32-byte limit, leading to a duplicate once truncated because some of the var names are not unique. How can I address this issue in SAS? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use the long data set, not a wide data set; create a report with either PROC REPORT or PROC TABULATE, and there is no 32 byte limit on column headings.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 17:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919801#M362297</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-11T17:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919803#M362299</link>
      <description>&lt;P&gt;I am preparing a report, so I need it in a wide format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 17:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919803#M362299</guid>
      <dc:creator>Rou</dc:creator>
      <dc:date>2024-03-11T17:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919812#M362301</link>
      <description>&lt;P&gt;Can you please provide an example data set (it doesn't have to be large, but it does have to be representative of your problem) and what you want the output to look like.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 17:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919812#M362301</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-11T17:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919820#M362303</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427127"&gt;@Rou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;VarName exceeds the 32-byte limit, leading to a duplicate once truncated because some of the var names are not unique. How can I address this issue in SAS? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sounds like you are using the wrong variable in the ID statement.&lt;/P&gt;
&lt;P&gt;You probably want something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= TALL ;
  by ID ResponseDate ResponseTime QuestionID ;
run;
proc transpose data=TALL out=WIDE(drop=_name_) prefix=Q ;
  by ID ResponseDate ResponseTime ;
  id QuestionID ;
  idlabel QuestionName;
  var &lt;SPAN&gt;Response ;&lt;/SPAN&gt;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2024 18:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919820#M362303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-11T18:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data from long to wide</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919862#M362316</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427127"&gt;@Rou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am preparing a report, so I need it in a wide format.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Most SAS Procs like Proc Report and Proc Tabulate work much better with long data. It's then the report procedure that allows you to create wide cross-tab reports.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 21:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-from-long-to-wide/m-p/919862#M362316</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-11T21:03:19Z</dc:date>
    </item>
  </channel>
</rss>

