<?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: Can this be done using proc transpose? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615363#M179994</link>
    <description>Thank you very much,&lt;BR /&gt;I made the response using proc transpose the solution because it answered my question, but I prefer this solution. Very concise and very understandable.</description>
    <pubDate>Mon, 06 Jan 2020 14:55:11 GMT</pubDate>
    <dc:creator>RoddyJ</dc:creator>
    <dc:date>2020-01-06T14:55:11Z</dc:date>
    <item>
      <title>Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615353#M179985</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset in the following format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ID    var1    var2    cat

1        1      1      A
2        0      1      B
1        0      0      A
2        1      1      B&lt;/PRE&gt;&lt;P&gt;I want the dataset in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ID    A_var1    A_var2    B_var1    B_var2    

1        1         1        0          1
2        0         0        1          1&lt;/PRE&gt;&lt;P&gt;i.e I want to transpose data based on categorical variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to do this using proc transpose but couldn't figure it out so I used the following code to get what I want:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_A;
set data;
where cat = "A";
rename var1 = A_var1 var2 = A_var2;
run;

data data_B;
set data;
where cat = "B";
rename var1 = B_var1 var2 = B_var2;
run;

data data_merged;
merge data_A data_B;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this using proc transpose or another more efficient method?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 09:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615353#M179985</guid>
      <dc:creator>RoddyJ</dc:creator>
      <dc:date>2020-01-07T09:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615357#M179988</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289103"&gt;@RoddyJ&lt;/a&gt;&amp;nbsp; Yes you can using Proc transpose but you need a double transpose like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID    var1    var2    cat $;
cards;
1        1      1      A
2        0      1      B
3        0      0      A
4        1      1      B
;

proc transpose data=have out=temp;
by id cat;
var var1 var2;
run;
proc transpose data=temp out=want(drop=_name_) delimiter=_;
by id ;
var col1;
id cat _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jan 2020 14:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615357#M179988</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-06T14:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615360#M179991</link>
      <description>&lt;P&gt;It can be done with a single datastep:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   merge 
     have(where=(cat='A') rename=(var1=A_var1 var2=A_var2))
     have(where=(cat='B') rename=(var1=B_var1 var2=B_var2))
     ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I do not think you can get the exact variable names that you want with PROC TRANSPOSE directly.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 14:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615360#M179991</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-01-06T14:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615361#M179992</link>
      <description>Thank you!</description>
      <pubDate>Mon, 06 Jan 2020 14:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615361#M179992</guid>
      <dc:creator>RoddyJ</dc:creator>
      <dc:date>2020-01-06T14:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615363#M179994</link>
      <description>Thank you very much,&lt;BR /&gt;I made the response using proc transpose the solution because it answered my question, but I prefer this solution. Very concise and very understandable.</description>
      <pubDate>Mon, 06 Jan 2020 14:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615363#M179994</guid>
      <dc:creator>RoddyJ</dc:creator>
      <dc:date>2020-01-06T14:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615382#M180002</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289103"&gt;@RoddyJ&lt;/a&gt;&amp;nbsp;: I'm confused! Was your example wrong? You had four records with IDs 1, 2, 3 and 4, but only want to end up with IDs 1 and 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 16:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615382#M180002</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-01-06T16:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615519#M180043</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289103"&gt;@RoddyJ&lt;/a&gt;&amp;nbsp;: You haven't answered my question, so I will respond regarding both scenarios (i.e., if your example was correct and if it wasn't).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both scenarios can be solved by using the %transpose macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the case where your example was incorrect, the following would provide the desired result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID    var1    var2    cat $;
  cards;
1        1      1      A
1        0      1      B
2        0      0      A
2        1      1      B
;
run;

filename tr url 'https://raw.githubusercontent.com/art297/transpose/master/transpose.sas';
%include tr ;

%transpose(data=have, out=want, by=ID, id=cat,
  var=var1 var2, delimiter=_, var_first=no)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Conversely, if your example was correct, then you could use the following data step, then application of the %transpose macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID    var1    var2    cat $;
  cards;
1        1      1      A
2        0      1      B
3        0      0      A
4        1      1      B
;
run;

data need;
  set have;
  id=round(id/2);
run;

filename tr url 'https://raw.githubusercontent.com/art297/transpose/master/transpose.sas';
%include tr ;

%transpose(data=need, out=want, by=ID, id=cat,
  var=var1 var2, delimiter=_, var_first=no)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope that helps,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 01:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615519#M180043</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-01-07T01:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be done using proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615600#M180067</link>
      <description>Yes I made a mistake in my original post, now amended. Thank you for pointing that out and for your solution!</description>
      <pubDate>Tue, 07 Jan 2020 09:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-this-be-done-using-proc-transpose/m-p/615600#M180067</guid>
      <dc:creator>RoddyJ</dc:creator>
      <dc:date>2020-01-07T09:06:04Z</dc:date>
    </item>
  </channel>
</rss>

