<?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 many responses to columns with binary response in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568936#M22904</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;! This works with one problem - my ID is set to 1 for all observations in the final dataset. Any idea why?&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2019 21:35:15 GMT</pubDate>
    <dc:creator>Melk</dc:creator>
    <dc:date>2019-06-25T21:35:15Z</dc:date>
    <item>
      <title>Transposing many responses to columns with binary response</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568904#M22900</link>
      <description>&lt;P&gt;I have longitudinal data that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Name&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I want it to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp;D&amp;nbsp; &amp;nbsp; &amp;nbsp;E&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a lot more names and IDs than what is sampled above. Can anyone advise how I can do this? I want all the possible names as a variable basically, and the response to be 0 or 1 for each ID, if it exists or not.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 19:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568904#M22900</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2019-06-25T19:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing many responses to columns with binary response</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568911#M22901</link>
      <description>&lt;P&gt;one way. Assumes the starting data is sorted by your ID variable. This also assumes than any values of your Name variable are also valid as variable names. If that is not the actual case with your data then you will need to provide details and whether you are going to use name literal variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
 input ID $    Name $;
 v=1;
datalines;
1        A
1        B
1        C
2        C
2        D
2        E
3        A
3        B
;

proc transpose data=have out=trans (drop=_name_);
 by id;
 var v;
 id name;
run;

data want;
   set trans;
   array __a _numeric_;
   do i=1 to dim(__a);
      __a[i] = not missing(__a[i]);
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;The odd __a array name is because I have no idea what actual values you have for your Name variable and am trying to avoid likely values as you can't have an array with the same name as a variable in the data set.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 19:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568911#M22901</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-25T19:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing many responses to columns with binary response</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568917#M22902</link>
      <description>If you search "creating dummy variables" on here, in the Library (not Community) you'll find a few really good resources to automate this. Do note, that most require you to have all levels in your data. If you don't, you'll need a different way to account for that, using CLASSDATA or a format are some options.</description>
      <pubDate>Tue, 25 Jun 2019 20:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568917#M22902</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-25T20:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing many responses to columns with binary response</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568936#M22904</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;! This works with one problem - my ID is set to 1 for all observations in the final dataset. Any idea why?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 21:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568936#M22904</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2019-06-25T21:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing many responses to columns with binary response</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568948#M22905</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140721"&gt;@Melk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;! This works with one problem - my ID is set to 1 for all observations in the final dataset. Any idea why?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;All I can say is data related (provide actual data) or a coding issue. Without seeing your code or data it is hard to diagnose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course if you simplified your starting data too much then there may be additional sorting required and more by variables for the sort and transpose.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 23:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568948#M22905</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-25T23:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing many responses to columns with binary response</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568951#M22906</link>
      <description>&lt;P&gt;One simple way is to use some "wallpaper" code with PROC SQL.&amp;nbsp; Like this:&lt;/P&gt;
&lt;PRE&gt;194  +create table want as select id
195  +,max(name="A" ) as A
196  +,max(name="B" ) as B
197  +,max(name="C" ) as C
198  +,max(name="D" ) as D
199  +,max(name="E" ) as E
200  +from have group by id order by id;
&lt;/PRE&gt;
&lt;P&gt;So that is easy to generate if you have a list of the possible values of NAME.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set names end=eof;
  file code;
  if _n_=1 then put 'create table want as select id';
  put ',max(name=' name :$quote. ') as ' name ;
  if eof then put 'from have group by id order by id;' ;
run;

proc sql noprint;
%include code / source2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't have a list of the possible values you can easily get a list of the values present in the current dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have(keep=name) out=names nodupkey;
  by name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 23:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transposing-many-responses-to-columns-with-binary-response/m-p/568951#M22906</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-25T23:36:01Z</dc:date>
    </item>
  </channel>
</rss>

