Hi all,
I tried to create a summary table for sashelp.class dataset, but i
am struck in the last step. Please help me????
Data
class;
set
sashelp.class;
run
;
proc
print data=class;
run
;
proc
format;
value
$sex
'F'='Female'
'M'='Male'
;
run
;
proc
format ;
value
age
low-
11='<11'
12-14='12-14'
15-high='>15'
;
run
;
proc
format;
value
height
low-
60='<60'
60-70='60-70'
70-high='>70'
;
run
;
proc
format;
value
weight
low-
80='<80'
80-120='80-120'
120-high='>120'
;
run
;
proc
freq data=class;
tables
sex /out=sex_f;
format
sex $sex.;
run
;
proc
freq data=class;
tables
age / out=age_f;
format
age age.;
run
;
proc
freq data=class;
tables
height /out=ht_f;
format
height height.;
run
;
proc
freq data=class;
tables
weight /out=wt_f;
format
weight weight.;
run
;
data
sex_f1 (drop = count percent);
set
sex_f;
length
text $50 value $20;
value=(count||
'('||put(percent,4.1)||'%)');
text=put(sex,
$sex.);
run
;
data
age_f1(drop = count percent);
set
age_f;
length
text $50 value $20;
value=(count||
'('||put(percent,4.1)||'%)');
text=put(age,
age.);
run
;
data
ht_f1(drop = count percent);
set
ht_f;
length
text $50 value $20;
value=(count||
'('||put(percent,4.1)||'%)');
text=put(height,
height.);
run
;
data
wt_f1(drop = count percent);
set
wt_f;
length
text $50 value $20;
value=(count||
'('||put(percent,4.1)||'%)');
text=put(weight,
weight.);
run
;
proc
print data=sex_f1;
run
;
proc
print data=age_f1;
run
;
proc
print data=ht_f1;
run
;
proc
print data=wt_f1;
run
;
data
final;
set sex_f1 age_f1 ht_f1 wt_f1;
drop sex age height weight;
run
;
proc
print data=final;
run
;
options ls=90;
proc report data=final nowindows headline spacing=1;
column text value;
define text/ "Groups" ;
define value / "count & percent" ;
run;
----------------------------------------------------------------------------------------------------------------------------------------------------------------
the report produced this way looks like this:
groups count & percent
female 9(47.4%)
male 10(52.6%)
<11 2(10.5%)
12-14 12(63.2%)
>15 5(26.3%)
and so on.....................................................for
height and weight
------------------------------------------------------------------------------------------
but i want the report to be like this:
groups count & percent
sex
female 9(47.4%)
male 10(52.6%)
Age
<11 2(10.5%)
12-14 12(63.2%)
>15 5(26.3%)
and so on..................................................
Can anyone tell me what to do in the report procedure to get the
required output.
Thanks,
Dolly
|
|
0
|
|
|
|
Reply
|
dolly
|
11/17/2010 11:18:25 PM |
|
On Nov 17, 3:18=A0pm, dolly <dollyko...@gmail.com> wrote:
> Hi all,
>
> =A0 =A0 I tried to create a summary table for sashelp.class dataset, but =
i
> am struck in the last step. Please help me????
>
> Data
> class;
>
> set
> sashelp.class;
>
> run
> ;
>
> proc
> print data=3Dclass;
>
> run
> ;
>
> proc
> format;
>
> value
> $sex
>
> 'F'=3D'Female'
>
> 'M'=3D'Male'
>
> ;
>
> run
> ;
>
> proc
> format ;
>
> value
> age
>
> low-
> 11=3D'<11'
>
> 12-14=3D'12-14'
>
> 15-high=3D'>15'
>
> ;
>
> run
> ;
>
> proc
> format;
>
> value
> height
>
> low-
> 60=3D'<60'
>
> 60-70=3D'60-70'
>
> 70-high=3D'>70'
>
> ;
>
> run
> ;
>
> proc
> format;
>
> value
> weight
>
> low-
> 80=3D'<80'
>
> 80-120=3D'80-120'
>
> 120-high=3D'>120'
>
> ;
>
> run
> ;
>
> proc
> freq data=3Dclass;
>
> tables
> sex /out=3Dsex_f;
>
> format
> sex $sex.;
>
> run
> ;
>
> proc
> freq data=3Dclass;
>
> tables
> age / out=3Dage_f;
>
> format
> age age.;
>
> run
> ;
> proc
> freq data=3Dclass;
>
> tables
> height /out=3Dht_f;
>
> format
> height height.;
>
> run
> ;
> proc
> freq data=3Dclass;
>
> tables
> weight /out=3Dwt_f;
>
> format
> weight weight.;
>
> run
> ;
> data
> sex_f1 (drop =3D count percent);
>
> set
> sex_f;
>
> length
> text $50 value $20;
>
> value=3D(count||
> '('||put(percent,4.1)||'%)');
>
> text=3Dput(sex,
> $sex.);
>
> run
> ;
>
> data
> age_f1(drop =3D count percent);
>
> set
> age_f;
>
> length
> text $50 value $20;
>
> value=3D(count||
> '('||put(percent,4.1)||'%)');
>
> text=3Dput(age,
> age.);
>
> run
> ;
> data
> ht_f1(drop =3D count percent);
>
> set
> ht_f;
>
> length
> text $50 value $20;
>
> value=3D(count||
> '('||put(percent,4.1)||'%)');
>
> text=3Dput(height,
> height.);
>
> run
> ;
> data
> wt_f1(drop =3D count percent);
>
> set
> wt_f;
>
> length
> text $50 value $20;
>
> value=3D(count||
> '('||put(percent,4.1)||'%)');
>
> text=3Dput(weight,
> weight.);
>
> run
> ;
>
> proc
> print data=3Dsex_f1;
>
> run
> ;
>
> proc
> print data=3Dage_f1;
>
> run
> ;
> proc
> print data=3Dht_f1;
>
> run
> ;
> proc
> print data=3Dwt_f1;
>
> run
> ;
> data
> final;
>
> set sex_f1 age_f1 ht_f1 wt_f1;
>
> drop sex age height weight;
>
> run
> ;
>
> proc
> print data=3Dfinal;
>
> run
> ;
>
> options ls=3D90;
> proc report data=3Dfinal nowindows headline spacing=3D1;
> column text value;
> define text/ "Groups" ;
> define value / "count & percent" ;
> run;
>
> -------------------------------------------------------------------------=
--=AD----------------------------------------------------------------------=
-----=AD----------
> the report produced this way looks like this:
> groups =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 count & percent
> female =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 9(47.4%)
> male =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 10(52.6%)
> <11 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2(10.5%)
> 12-14 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A012(63.2%)>15 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 5(26.3%)
>
> and so on.....................................................for
> height and weight
>
> -------------------------------------------------------------------------=
--=AD---------------
> but i want the report to be like this:
>
> groups =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0count &=
percent
>
> sex
> =A0 =A0 =A0 female =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 9(47.4=
%)
> =A0 =A0 =A0 male =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 10(5=
2.6%)
> Age
> =A0 =A0 =A0 <11 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 2=
(10.5%)
> =A0 =A0 =A012-14 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A012(63=
..2%)
> =A0 =A0 =A0 >15 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 5=
(26.3%)
> and so on..................................................
>
> Can anyone tell me what to do in the report procedure to get the
> required output.
>
> Thanks,
> Dolly
You don't need separated proc format statement, you only need one proc
format statement, then followed
by separated value statement. To get the indent, the easiest way is to
use proc tabulate:
proc format;
value $sex
'F'=3D'Female'
'M'=3D'Male';
value age
low-11=3D'<11'
12-14=3D'12-14'
15-high=3D'>15';
value height
low- 60=3D'<60'
60-70=3D'60-70'
70-high=3D'>70';
value weight
low- 80=3D'<80'
80-120=3D'80-120'
120-high=3D'>120';
data class;
set sashelp.class;
dumsex=3D'Sex';
dumage=3D'Age';
dumweight=3D'Weight';
run;
proc tabulate data=3Dclass noseps;
class dumsex dumage dumweight sex age weight;
table dumsex*sex=3D'Sex'
dumage*age=3D'Age'
dumweight*weight=3D'Weight', (n=3D'n'*f=3D3. pctn=3D'%'*f=3D5.1)
/ rts=3D20 indent=3D4 box=3D'Group';
format sex $sex. age age. weight weight.;
run;
------------------------------
|Group | n | % |
|------------------+---+-----|
|Sex | | |
| Female | 9| 47.4|
| Male | 10| 52.6|
|Age | | |
| <11 | 2| 10.5|
| 12-14 | 12| 63.2|
| >15 | 5| 26.3|
|Weight | | |
| <80 | 2| 10.5|
| 80-120 | 14| 73.7|
| >120 | 3| 15.8|
------------------------------
HTH
Ya
|
|
0
|
|
|
|
Reply
|
Ya
|
11/18/2010 12:24:18 AM
|
|
|
1 Replies
336 Views
(page loaded in 0.076 seconds)
|