Date: Tue, 8 Jul 2008 22:11:47 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Subject: Re: PROC FREQ AND TRANSPOSE
On Tue, 8 Jul 2008 06:32:27 -0700, Jerry <lihais@GMAIL.COM> wrote:
>Hi Mike,
>
>Thanks a lot for your input!
>
>The Proc Summary with COMPLETETYPES and the SPARSE solution in PROC
>FREQ work well. But when I add BY SOC, SPARSE solution have no effect
>on the result. This is my original procedure:
>
>PROC FREQ DATA=AE;
> PREFERRED*SEVERITY/SPARSE OUT=T;
> BY SOC;/*SOC is the upper level of preferred*/
>RUN;
>
>Any idea about this issue?
A BY statement has the effect of completely segregating the processing for
each group. The BY mechanism has no knowledge about the particular features
of the procedure in use, so it cannot possibly extend their effects across
group boundaries.
Just include SOC in the TABLES specification.
tables soc * preferred * severity.
Example:
proc format;
value height low-60 = 'Low' other = 'High';
value weight low-99 = 'Low' other = 'High';
run;
proc freq data=sashelp.class;
format height height. weight weight.;
tables sex * age * height * weight / sparse out=t;
run;
You will get 48 observation (2 sexes * 2 height ranges * 2 weight ranges * 6
ages).
>
>Best,
>Jerry
>
>
>
>
>On Jul 7, 4:31 pm, ms...@albany.edu (Mike Zdeb) wrote:
>> hi ... just a follow-up to the SPARSE solution to get zeroes in PROC FREQ
output ... that depends
>> on having at least one observation in your data set at each level of the
variables in the table
>> statement ... if you don't, you can replace ...
>>
>> proc freq data=sashelp.class;
>> table sex*age / sparse out=t;
>> run;
>>
>> proc transpose data=t out=tt (drop=_:) prefix=age;
>> var count;
>> by sex;
>> id age;
>> run;
>>
>> proc print data=tt;
>> run;
>>
>> with PROC SUMMARY, COMPLETETYPES, and PRELOADFMT --- for example, there
are no 10 or 17 year olds
>> in the data set, but you can get zeroes for them in TRANSPOSE output
with ...
>>
>> proc format;
>> value age 10 = '10' 17 = '17' ;
>> run;
>>
>> proc summary data=sashelp.class nway completetypes;
>> class sex;
>> class age / preloadfmt;
>> output out=t;
>> format age age.;
>> run;
>>
>> proc transpose data=t out=tt (drop=_:) prefix=age;
>> var _freq_;
>> by sex;
>> id age;
>> run;
>>
>> proc print data=tt;
>> run;
>>
>> --
>> Mike Zdeb
>> U@Albany School of Public Health
>> One University Place
>> Rensselaer, New York 12144-3456
>> P/518-402-6479 F/630-604-1475
>>
>>
>>
>> > On Mon, 7 Jul 2008 13:06:21 -0700, Jerry <lih...@GMAIL.COM> wrote:
>>
>> >>Hello all,
>>
>> >>Sorr for the part of question!
>>
>> >>I got the result from the proc freq.
>>
>> >>Preferred Term severity count
>>
>> >>Dizziness mild 1
>> >>Dizziness severe 2
>> >>Headache moderate 2
>> >>Headache severe 3
>> >>Sensory loss mild 5
>> >>Lethargy mild 4
>> >>Lethargy moderate 7
>> >>Lethargy Severe 6
>>
>> >>I want to transpose to get the result like:
>>
>> >>Preferred term mild modereate severe
>> >>Dizziness 1 0 2
>> >>headache 0 2 3
>> >>sensory loss 0 0 3
>> >>leahargy 4 7 6
>>
>> >>How can I do the transpose and get the result for missing level of
>> >>severity?
>>
>> >>Thanks in advance!- Hide quoted text -
>>
>> - Show quoted text -