<?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: How do I transpose a data set that has multiple values for an ID variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829890#M327892</link>
    <description>Thanks!</description>
    <pubDate>Tue, 23 Aug 2022 14:32:45 GMT</pubDate>
    <dc:creator>Hello_there</dc:creator>
    <dc:date>2022-08-23T14:32:45Z</dc:date>
    <item>
      <title>How do I transpose a data set that has multiple values for an ID variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829878#M327889</link>
      <description>&lt;P&gt;I have this data set that I want to transform so that it's one row per ID. The problem is that there are multiple values for the an ID variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the data set in question:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
infile datalines dsd dlm=",";
	input id $ category $ val $;
datalines;
001, color, blue
001, color, red
002, color, orange
003, color, red
003, color, orange,
003, color, blue
004, color, aqua
005, color, purple
; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ideally, I would want it so it looks like:&lt;/P&gt;
&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp;category val1 &amp;nbsp; &amp;nbsp; &amp;nbsp; val2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val3&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp;color &amp;nbsp; &amp;nbsp; &amp;nbsp; blue &amp;nbsp; &amp;nbsp; &amp;nbsp; red&lt;/P&gt;
&lt;P&gt;002 &amp;nbsp;color &amp;nbsp; &amp;nbsp; &amp;nbsp;orange&lt;/P&gt;
&lt;P&gt;003 &amp;nbsp;color &amp;nbsp; &amp;nbsp; &amp;nbsp;red &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;orange &amp;nbsp; &amp;nbsp; blue&lt;/P&gt;
&lt;P&gt;004 &amp;nbsp;color &amp;nbsp; &amp;nbsp; aqua&lt;/P&gt;
&lt;P&gt;005 &amp;nbsp;color &amp;nbsp; &amp;nbsp; purple&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 14:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829878#M327889</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-08-23T14:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose a data set that has multiple values for an ID variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829887#M327890</link>
      <description>&lt;P&gt;PROC TRANSPOSE can handle that example very easily.&amp;nbsp; Perhaps you over simplified your example?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
	input id $ category $ val $;
datalines;
001  color  blue
001  color  red
002  color  orange
003  color  red
003  color  orange 
003  color  blue
004  color  aqua
005  color  purple
; 

proc transpose data=have1 out=want1(drop=_name_) prefix=VAL ;
  by id category ;
  var val;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id     category    VAL1      VAL2      VAL3

 1     001     color      blue      red
 2     002     color      orange
 3     003     color      red       orange    blue
 4     004     color      aqua
 5     005     color      purple&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2022 14:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829887#M327890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-23T14:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose a data set that has multiple values for an ID variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829890#M327892</link>
      <description>Thanks!</description>
      <pubDate>Tue, 23 Aug 2022 14:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829890#M327892</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-08-23T14:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose a data set that has multiple values for an ID variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829894#M327893</link>
      <description>&lt;P&gt;For your given example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have1 out=trans (drop=_name_)
  prefix=val;
   by id category;
   var val;
run;&lt;/PRE&gt;
&lt;P&gt;Transpose uses the BY variables to create groupings.&lt;/P&gt;
&lt;P&gt;The default behavior is to use the Prefix (defaults to col) as the name of the transposed variables with an increment for number of values in the by group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you were concerned with the ID statement that is for a variable used to NAME output variables and generally doesn't allow multiple values per By group.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 14:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829894#M327893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-23T14:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose a data set that has multiple values for an ID variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829896#M327894</link>
      <description>&lt;P&gt;Thanks for your reply!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 14:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-transpose-a-data-set-that-has-multiple-values-for-an-ID/m-p/829896#M327894</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-08-23T14:36:52Z</dc:date>
    </item>
  </channel>
</rss>

