<?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: Create new SAS table with count number of observations per subject in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470953#M120567</link>
    <description>&lt;P&gt;Hi, Simba:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want SAS dataset by submitting Mr. PaigeMiller's code, you should use OUT= option in REPORT Procedure.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Destination;
cards;
aa	1
aa	1
aa	1
aa	2
aa	1
bb	1
bb	3
bb	3
bb	4
bb	4
cc	1
cc	2
cc	3
cc	1
cc	1
cc	1
dd	4
dd	4
dd	4
dd	1
;
proc report data=have out=want;
    columns id destination;
    define id/group;
    define destination/across;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jun 2018 01:04:08 GMT</pubDate>
    <dc:creator>KentaMURANAKA</dc:creator>
    <dc:date>2018-06-18T01:04:08Z</dc:date>
    <item>
      <title>Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470847#M120516</link>
      <description>&lt;P&gt;Hi, I have dataset below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Destination&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aa&lt;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dd&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am sure there is a way to use Proc sql. I just cant get it to work&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 04:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470847#M120516</guid>
      <dc:creator>Simba</dc:creator>
      <dc:date>2018-06-17T04:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470849#M120518</link>
      <description>&lt;P&gt;Hi, Simba:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you use SQL procedure, you can use TRANSPOSE procedure after submitting the code below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table work.stat_2 as
    select id, count(destination)
    from work.test
    group by id, destination;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm sorry, but I'm not familiar with SQL well, so I made Proc FREQ &amp;amp; TRANSPOSE Used version.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    input id$ destination @@;
    datalines;
    aa 1 aa 1 aa 1 aa 2 aa 1
    bb 1 bb 3 bb 3 bb 4 bb 4
    cc 1 cc 2 cc 3 cc 1 cc 1 cc 1
    dd 4 dd 4 dd 4 dd 1
    ;
run;
proc freq data=test noprint;
    tables destination / out=stat_1(drop=percent);
    by id;
run;
proc sort data=stat_1 nodupkey out=dummy(keep=id);
    by id;
run;
data dummy_1;
    set dummy;
    do destination=1 to 4 by 1;
        count=0;
        output;
    end;
run;
data stat_1_1;
    attrib cntc
        length=$200.;
    merge dummy_1(in=a)
          stat_1(in=b)
          ;
    by id destination;
    if a;
    if count notin (., 0) then cntc=cats(put(round(count), best.));
    else cntc="";
run;
proc transpose data=stat_1_1 prefix=dest_count out=stat_1_2;
    var cntc;
    by id;
    id destination;
run;&lt;/CODE&gt;&lt;/PRE&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>Sun, 17 Jun 2018 05:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470849#M120518</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2018-06-17T05:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470852#M120520</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Destination;
cards;
aa	1
aa	1
aa	1
aa	2
aa	1
bb	1
bb	3
bb	3
bb	4
bb	4
cc	1
cc	2
cc	3
cc	1
cc	1
cc	1
dd	4
dd	4
dd	4
dd	1
;

proc freq data=have;
by id;
tables destination/out=temp;
run;

proc transpose data=temp out=want(drop=_:) prefix=Dest_count;
by id;
var count;
id  destination ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jun 2018 05:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470852#M120520</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-17T05:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470857#M120521</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
    columns id destination;
    define id/group;
    define destination/across;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jun 2018 11:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470857#M120521</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-17T11:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470949#M120564</link>
      <description>&lt;P&gt;Thank you KentaMURANKA. This works great!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 00:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470949#M120564</guid>
      <dc:creator>Simba</dc:creator>
      <dc:date>2018-06-18T00:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470950#M120565</link>
      <description>Thank you for your help. Appreciate it. This code counts the obs per ID but reports it as individual tables per ID.</description>
      <pubDate>Mon, 18 Jun 2018 00:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470950#M120565</guid>
      <dc:creator>Simba</dc:creator>
      <dc:date>2018-06-18T00:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470951#M120566</link>
      <description>Thank you PaigeMiller. This code gives me a report table with the values correctly tabulated. The code by KentaMURANKA gives me the same response but as a SAS dataset that can be further analyzed.</description>
      <pubDate>Mon, 18 Jun 2018 00:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470951#M120566</guid>
      <dc:creator>Simba</dc:creator>
      <dc:date>2018-06-18T00:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470953#M120567</link>
      <description>&lt;P&gt;Hi, Simba:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want SAS dataset by submitting Mr. PaigeMiller's code, you should use OUT= option in REPORT Procedure.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Destination;
cards;
aa	1
aa	1
aa	1
aa	2
aa	1
bb	1
bb	3
bb	3
bb	4
bb	4
cc	1
cc	2
cc	3
cc	1
cc	1
cc	1
dd	4
dd	4
dd	4
dd	1
;
proc report data=have out=want;
    columns id destination;
    define id/group;
    define destination/across;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 01:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470953#M120567</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2018-06-18T01:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470954#M120568</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 01:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470954#M120568</guid>
      <dc:creator>Simba</dc:creator>
      <dc:date>2018-06-18T01:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470955#M120569</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216001"&gt;@Simba&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you PaigeMiller. This code gives me a report table with the values correctly tabulated. The code by KentaMURANKA gives me the same response but as a SAS dataset that can be further analyzed.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And a simple change to my code gives you the SAS dataset that you want. I will leave that as a homework assignment for you, to look up in the documentation how to get the data set out from PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, your original request was not for a SAS dataset, it was for a "SAS table" (your words, not mine) and I gave you code for a table.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 01:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/470955#M120569</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-18T01:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/471006#M120594</link>
      <description>&lt;P&gt;Here's how we can do it with PROC SQL ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
	create table test1 as 
	select id, DESTINATION, count(destination) as cnt 
	from test group by 1,2 ; quit;

proc transpose data=test1 prefix=dest_count out=test2 (drop=_name_)  ;
	var cnt ;
	by id ;
	id destination ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jun 2018 09:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/471006#M120594</guid>
      <dc:creator>PraneethSrinivas</dc:creator>
      <dc:date>2018-06-18T09:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create new SAS table with count number of observations per subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/471255#M120686</link>
      <description>Thank you PraneethSrinivas. This works perfectly! Appreciate all your help.</description>
      <pubDate>Mon, 18 Jun 2018 22:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-SAS-table-with-count-number-of-observations-per/m-p/471255#M120686</guid>
      <dc:creator>Simba</dc:creator>
      <dc:date>2018-06-18T22:59:19Z</dc:date>
    </item>
  </channel>
</rss>

