<?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: Freq table help? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10065#M892</link>
    <description>proc sort data=sample ;&lt;BR /&gt;
by facility_id ;&lt;BR /&gt;
run;&lt;BR /&gt;
*if your data already sorted by facility_id, you don't need sort it again.;&lt;BR /&gt;
* in the result, the restr1 will be the freqency restr1 in (0 1),  the restr1_count will be the freqency for restr1=1;&lt;BR /&gt;
* same for restr2;&lt;BR /&gt;
*if there are no missing values exist, restr1 will be equqal to restr2;&lt;BR /&gt;
&lt;BR /&gt;
data result;&lt;BR /&gt;
set sample;&lt;BR /&gt;
by facility_id;&lt;BR /&gt;
drop count1 count2 ssn;&lt;BR /&gt;
if first.facility_id then do;&lt;BR /&gt;
count1=0;&lt;BR /&gt;
count2=0;&lt;BR /&gt;
restr1_count=0;&lt;BR /&gt;
restr2_count=0;&lt;BR /&gt;
end;&lt;BR /&gt;
if restr1 eq 1  then restr1_count+1;&lt;BR /&gt;
else if restr1 eq 0 then count1+1;&lt;BR /&gt;
if restr2 eq 1 then restr2_count+1;&lt;BR /&gt;
else if restr2 eq 0 then count2+1;&lt;BR /&gt;
if last.facility_id then do;&lt;BR /&gt;
restr1=sum(count1,restr1_count);&lt;BR /&gt;
restr2=sum(count2,restr2_count);&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
    <pubDate>Mon, 04 Oct 2010 16:15:27 GMT</pubDate>
    <dc:creator>SUN59338</dc:creator>
    <dc:date>2010-10-04T16:15:27Z</dc:date>
    <item>
      <title>Freq table help?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10063#M890</link>
      <description>Good morning, &lt;BR /&gt;
&lt;BR /&gt;
I am trying to code for a situation I have never seen before. &lt;BR /&gt;
I am trying to display a frequency table of different facilities and the amount of physical restraints used divided by types. IE&amp;gt;&lt;BR /&gt;
&lt;BR /&gt;
(Facility ID)         (Restr 1)   	(Restr 2)&lt;BR /&gt;
1	                     42	           35&lt;BR /&gt;
2	                     342	           32&lt;BR /&gt;
3	                     23423	           343&lt;BR /&gt;
&lt;BR /&gt;
Each row is considered an admission to the facility, having a patient SSN attached to it. I also need to determine how many patients per restraint per facility. This would be determined by how many different social security numbers per restraint per facility ID , and somehow doing a count function. &lt;BR /&gt;
The data is similar to this….&lt;BR /&gt;
&lt;BR /&gt;
(Facility ID)	   ( SSN)	   ( Restr 1)	  (Restr 2)&lt;BR /&gt;
1	                    1233	        1	            0&lt;BR /&gt;
1	                    1233	        1	            0&lt;BR /&gt;
1	                    1554	        0	            1 &lt;BR /&gt;
2	                    1111	        1	            0&lt;BR /&gt;
2	                    1224	        0	            1&lt;BR /&gt;
2	                    1224	        0	            1&lt;BR /&gt;
Legend: restraint1=0, no restraint used, restraint 1=1, restraint used&lt;BR /&gt;
&lt;BR /&gt;
I want a table to be generated from the above sample data to look like this…&lt;BR /&gt;
&lt;BR /&gt;
(Facility ID)   (Restr1)	(# of Patients used restr1) (Restr 2)  (# of Patients used restr2)&lt;BR /&gt;
       1	         2	                 1	                    1                    	1&lt;BR /&gt;
       2	         1	                 1	                    2	                        1&lt;BR /&gt;
&lt;BR /&gt;
I am using enterprise as well. I suppose it has something to do with DupOUT but I am not as familiar with that function.  Any help would be greatly appreciated!</description>
      <pubDate>Thu, 30 Sep 2010 15:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10063#M890</guid>
      <dc:creator>slivingston1</dc:creator>
      <dc:date>2010-09-30T15:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table help?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10064#M891</link>
      <description>I don't think you can do what you need in one step.&lt;BR /&gt;
But here's something to help you get started.  It will generate two tables, one with counts and one with distinct counts. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
*input sample data;&lt;BR /&gt;
data sample;&lt;BR /&gt;
input facility_id ssn rstr_1 rstr_2;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1233 1 0&lt;BR /&gt;
1 1233 1 0&lt;BR /&gt;
1 1554 0 1 &lt;BR /&gt;
2 1111 1 0&lt;BR /&gt;
2 1224 0 1&lt;BR /&gt;
2 1224 0 1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*# of restraints;&lt;BR /&gt;
proc means data=sample sum;&lt;BR /&gt;
	class facility_id;&lt;BR /&gt;
	var rstr_1 rstr_2;&lt;BR /&gt;
	output out=keep1 sum=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*get rid of duplicates;&lt;BR /&gt;
proc sort data=sample ;&lt;BR /&gt;
	by facility_id ssn rstr_1 rstr_2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=sample noduprecs dupout=duplicates;&lt;BR /&gt;
	by facility_id ssn rstr_1 rstr_2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*unique counts;&lt;BR /&gt;
proc means data=sample sum;&lt;BR /&gt;
	class facility_id;&lt;BR /&gt;
	var rstr_1 rstr_2;&lt;BR /&gt;
	output out=keep2 sum=;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 30 Sep 2010 22:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10064#M891</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-09-30T22:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table help?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10065#M892</link>
      <description>proc sort data=sample ;&lt;BR /&gt;
by facility_id ;&lt;BR /&gt;
run;&lt;BR /&gt;
*if your data already sorted by facility_id, you don't need sort it again.;&lt;BR /&gt;
* in the result, the restr1 will be the freqency restr1 in (0 1),  the restr1_count will be the freqency for restr1=1;&lt;BR /&gt;
* same for restr2;&lt;BR /&gt;
*if there are no missing values exist, restr1 will be equqal to restr2;&lt;BR /&gt;
&lt;BR /&gt;
data result;&lt;BR /&gt;
set sample;&lt;BR /&gt;
by facility_id;&lt;BR /&gt;
drop count1 count2 ssn;&lt;BR /&gt;
if first.facility_id then do;&lt;BR /&gt;
count1=0;&lt;BR /&gt;
count2=0;&lt;BR /&gt;
restr1_count=0;&lt;BR /&gt;
restr2_count=0;&lt;BR /&gt;
end;&lt;BR /&gt;
if restr1 eq 1  then restr1_count+1;&lt;BR /&gt;
else if restr1 eq 0 then count1+1;&lt;BR /&gt;
if restr2 eq 1 then restr2_count+1;&lt;BR /&gt;
else if restr2 eq 0 then count2+1;&lt;BR /&gt;
if last.facility_id then do;&lt;BR /&gt;
restr1=sum(count1,restr1_count);&lt;BR /&gt;
restr2=sum(count2,restr2_count);&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 04 Oct 2010 16:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10065#M892</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-10-04T16:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table help?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10066#M893</link>
      <description>If I understand that you are looking for a count of valid records for each rstr (non-missing) and the number of ones, then try this for generating a table of frequencies.&lt;BR /&gt;
&lt;BR /&gt;
/* using one of the example data sets above*/&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=sample;&lt;BR /&gt;
class facility_id;&lt;BR /&gt;
var rstr_1 rstr_2;&lt;BR /&gt;
table facility_id, (rstr_1 rstr_2)*(n='Patients' sum='Restrained');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
If this looks like what you want but need an output dataset tabulate supports output datasets as well.</description>
      <pubDate>Tue, 05 Oct 2010 16:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-table-help/m-p/10066#M893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2010-10-05T16:18:49Z</dc:date>
    </item>
  </channel>
</rss>

