<?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: Transpose data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307543#M65891</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
  input Neuroses $ Psychoses $ SignsSimpt $ Antisocial $ Depression $ Anomalies_Neurological $ ;
datalines;
40891863A 51330023A 84501233A 77699061A 32596703A 21189153A
77699061A 80328413A 61073933A 81441794A 10418753A 14050203A
13885263A 57306061A 08707021A 58633031A 44606543A 22757783A
01247023A 42638553A 32907423A 47662551A 52508373A 30956893A
44606543A 58393081A 64904003A 28133791A 20982933A 75235783A
;
run;
data have;
 set have;
 n+1;
run;
proc transpose data=have out=temp;
 by n;
 var _character_;
run;
proc sql;
create table temp1 as
select col1,count(distinct _name_) as n_condition
 from temp
  group by col1;

create table want as
select n_condition,count(*) as n_member
 from temp1
  group by n_condition;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Oct 2016 02:27:11 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-10-27T02:27:11Z</dc:date>
    <item>
      <title>Transpose data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307505#M65875</link>
      <description>&lt;P&gt;Good afternoon all! Here is the sample dataset (real data has 9 variable conditions)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;input Neuroses $ Psychoses $&amp;nbsp;SignsSimpt $&amp;nbsp;Antisocial $ Depression $&amp;nbsp;Anomalies_Neurological&amp;nbsp;$ ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;datalines;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;40891863A 51330023A 84501233A 77699061A 32596703A 21189153A&lt;BR /&gt;77425921A 80328413A 61073933A 81441794A 10418753A 14050203A&lt;BR /&gt;13885263A 57306061A 08707021A 58633031A 44606543A 22757783A&lt;BR /&gt;01247023A 42638553A 32907423A 47662551A 52508373A 30956893A&lt;BR /&gt;44606543A 58393081A 64904003A 28133791A 20982933A 75235783A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So basically under each diagnosis condition, there are patient id's. A patient could have more than one condition. What i want is an output which tells that how many patients have 9 conditions at once, 8 conditions at once, 7 conditions at once and so on. So, essentially something like this&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No of conditions &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; 8 &amp;nbsp; 9&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No of members &amp;nbsp;450 &amp;nbsp; &amp;nbsp;378 &amp;nbsp; &amp;nbsp;245 &amp;nbsp;200 145 100 56 &amp;nbsp;34 12&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I tried playing around with simple proc transpose, but im not going anywhere. Thanks so much!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 21:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307505#M65875</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-10-26T21:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307528#M65881</link>
      <description>&lt;P&gt;Let convert file HAVE to HELP with two variables: &lt;STRONG&gt;Diagnosys&lt;/STRONG&gt; and &lt;STRONG&gt;Patient_ID,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;thus can be done in a code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data HELP;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set HAVE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Patient_ID = Neuroses; &amp;nbsp; &amp;nbsp; &amp;nbsp;Diagnosys = 'Neuroses'; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Patient_ID = Psychoses; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Diagnosys = 'Psychoses'; &amp;nbsp;output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ... etc all 9 kinds of diagnosys ....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then use PROC FREQ with the OUT option twice to get your wanted output:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1st time TABLE Patient_ID &amp;nbsp;(assuming no patients with duplicates of same diagnosys)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2nd time TABLE &amp;nbsp;Count &amp;nbsp; &amp;nbsp; &amp;nbsp; (or _FREQ_ depends on SAS version)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 00:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307528#M65881</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-27T00:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307533#M65882</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
  input Neuroses $ Psychoses $ SignsSimpt $ Antisocial $ Depression $ Anomalies_Neurological $ ;
datalines;
40891863A 51330023A 84501233A 77699061A 32596703A 21189153A
77699061A 80328413A 61073933A 81441794A 10418753A 14050203A
13885263A 57306061A 08707021A 58633031A 44606543A 22757783A
01247023A 42638553A 32907423A 47662551A 52508373A 30956893A
44606543A 58393081A 64904003A 28133791A 20982933A 75235783A
run;&lt;BR /&gt;
data NORMAL;
  set HAVE;
  length CONDITION $32;
  do CONDITION='Neuroses','Psychoses','SignsSimpt','Antisocial','Depression','Anomalies_Neurological'; 
    PATIENT=vvaluex(CONDITION); output;
  end;
  keep CONDITION PATIENT;
run;     &lt;BR /&gt;
proc sql;
  create table COUNTS as select count(*) as NB_CONDITIONS from NORMAL group by PATIENT;
  create table WANT as select NB_CONDITIONS, count(*) as NB_PATIENTS from COUNTS group by NB_CONDITIONS;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 00:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307533#M65882</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-10-27T00:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307543#M65891</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
  input Neuroses $ Psychoses $ SignsSimpt $ Antisocial $ Depression $ Anomalies_Neurological $ ;
datalines;
40891863A 51330023A 84501233A 77699061A 32596703A 21189153A
77699061A 80328413A 61073933A 81441794A 10418753A 14050203A
13885263A 57306061A 08707021A 58633031A 44606543A 22757783A
01247023A 42638553A 32907423A 47662551A 52508373A 30956893A
44606543A 58393081A 64904003A 28133791A 20982933A 75235783A
;
run;
data have;
 set have;
 n+1;
run;
proc transpose data=have out=temp;
 by n;
 var _character_;
run;
proc sql;
create table temp1 as
select col1,count(distinct _name_) as n_condition
 from temp
  group by col1;

create table want as
select n_condition,count(*) as n_member
 from temp1
  group by n_condition;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Oct 2016 02:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307543#M65891</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-27T02:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307558#M65897</link>
      <description>&lt;P&gt;Thanks Chriznz and Ksharp. Both the solutions worked, i understood Ksharp's better as im not aware of the function used by chrisnz. I will dig deeper into it to learn more.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 04:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data/m-p/307558#M65897</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-10-27T04:28:04Z</dc:date>
    </item>
  </channel>
</rss>

