Date: Mon, 21 Feb 2011 15:31:38 -0600
Reply-To: "Data _null_;" <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Data _null_;" <iebupdte@GMAIL.COM>
Subject: Re: summary transposition problem
In-Reply-To: <201102211910.p1LHHkGM030769@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=windows-1252
I like the output from PROC FREQ. The ODS OUTPUT stacked tables
datasets provides the necessary data to make this pretty easy. This
also extents to two-way freqs with very little work. Plus data type
is not an issue. It could be as simple as coalesceC(of F_:) but I
don't usually use one-way tables and F_ is only for one-way tables.
proc freq data=sashelp.class;
tables sex age;
ods output OneWayFreqs=owf;
run;
data owf;
set owf;
by table notsorted;
length name_order 8 variable_name $32 variable_category $16 category_order 8;
variable_name = scan(table,-1,' ');
if first.table then do;
name_order + 1;
category_order = 0;
end;
category_order + 1;
variable_category = left(vvalueX(variable_name));
run;
proc print;
run;
On Mon, Feb 21, 2011 at 1:10 PM, Evan Davies <esdav2@wm.edu> wrote:
> Let’s say I have a data set like this:
>
> Id gender eyecolor
> 1 M Blue
> 2 F Green
> 3 M Gray
> 4 F Blue
>
> And want to get this:
>
> Varname varcategory summaryN
> Gender M 2
> Gender F 2
> Eyecolor Blue 2
> Eyecolor Green 1
> Eyecolor Gray 1
>
> How would I go about it?
>
> I can use proc tab or proc summary to get this:
>
> Gender Eyecolor summaryN
> M . 2
> F . 2
> . Blue 2
> . Green 1
> . Gray 1
>
> Which is only halfway.
>
> I can use a coalesce function to get:
>
> Varname summaryN
> M 2
> F 2
> Blue 2
> Green 1
> Gray 1
>
> But that doesn’t identify the variable that the values came from.
>
> Key point: I don’t want to have to hard code gender, eyecolor, etc into a
> process – I need to do this to multiple datasets with different variables,
> and want the categories to define themselves generically, as variable_name,
> variable_category, and var_summaryN.
>
|