<?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 data reshaping in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953456#M42850</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;my have data is the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
     input col_a col_b $ col_c :date9.;
datalines;
123 123456789ABC . 
123 123456789DEF 15AUG2014
123 123456789GHI 30SEP2014 
456 987654321ABC 20DEC2013
456 987654321DEF 31JAN2014
456 987654321GHI 02FEB2014
;​&lt;/LI-CODE&gt;&lt;P&gt;I would like to reshape this data where the values of col_b are transposed to new columns and the minimum of the date column per col_a is taken as date column. I tried multiple solution suggestions I found here in the communities but they didn't work out.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data want;
     input col_a col_b_1 $ col_b_2 $ col_b_3 $ col_c :date9.;
datalines;
123 123456789ABC 123456789DEF 123456789GHI 15AUG2014
456 987654321ABC 987654321DEF 987654321GHI 20DEC2013
;​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Any help would be highly appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2024 20:27:17 GMT</pubDate>
    <dc:creator>nbora</dc:creator>
    <dc:date>2024-12-12T20:27:17Z</dc:date>
    <item>
      <title>data reshaping</title>
      <link>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953456#M42850</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;my have data is the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
     input col_a col_b $ col_c :date9.;
datalines;
123 123456789ABC . 
123 123456789DEF 15AUG2014
123 123456789GHI 30SEP2014 
456 987654321ABC 20DEC2013
456 987654321DEF 31JAN2014
456 987654321GHI 02FEB2014
;​&lt;/LI-CODE&gt;&lt;P&gt;I would like to reshape this data where the values of col_b are transposed to new columns and the minimum of the date column per col_a is taken as date column. I tried multiple solution suggestions I found here in the communities but they didn't work out.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data want;
     input col_a col_b_1 $ col_b_2 $ col_b_3 $ col_c :date9.;
datalines;
123 123456789ABC 123456789DEF 123456789GHI 15AUG2014
456 987654321ABC 987654321DEF 987654321GHI 20DEC2013
;​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Any help would be highly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 20:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953456#M42850</guid>
      <dc:creator>nbora</dc:creator>
      <dc:date>2024-12-12T20:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: data reshaping</title>
      <link>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953461#M42853</link>
      <description>&lt;P&gt;First thing is do you really need that new data set? As in, how do you intend to use the result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Often changing from "long" to "wide" is not a good choice for most analysis or reporting in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;Proc transpose data=have out=trans (drop=_name_)
   prefix=Col_b_;
   by col_a;
   var col_b;
run;
proc summary data=have nway;
   by col_a;
   var col_c;
   output out=summary(drop=_:) min=;
run;

data want;
   merge trans summary ;
   by col_a;
run;&lt;/PRE&gt;
&lt;P&gt;However there might be some issues around desired results if any of the Col_b are duplicated within the value of col_a of if the order of the Col_b values in the output needs to be in a specific order different than order of appearance in the Have dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Proc summary has a drop dataset option because there would be other variables included in the output set&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 20:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953461#M42853</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-12T20:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: data reshaping</title>
      <link>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953471#M42855</link>
      <description>&lt;P&gt;Reshaping the data like this only make programming the next step(s) harder. Don't do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tell us what you are going to do with this data after you re-shape it, and we can give you better ideas about how to handle this data.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 21:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953471#M42855</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-12T21:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: data reshaping</title>
      <link>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953474#M42857</link>
      <description>&lt;P&gt;PROC SUMMARY can do that directly (as long as the number of values per BY group is small enough).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have ;
  by col_a;
  output out=want(drop=_type_ _freq_)  idgroup(out[3] (col_b)=) min(col_c)=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know if 3 is the right number of new COL_B variables then count first and put the number into macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
 select max(nobs) into :nobs trimmed
   from (select count(*) as nobs from have group by col_a)
 ;
quit;

proc summary data=have ;
  by col_a;
  output out=want(drop=_type_ _freq_)  idgroup(out[&amp;amp;nobs] (col_b)=) min(col_c)=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Read this classic paper:&amp;nbsp;&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings10/102-2010.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings10/102-2010.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 23:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/data-reshaping/m-p/953474#M42857</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-12T23:06:03Z</dc:date>
    </item>
  </channel>
</rss>

