education in proc tabulate - sascommunity proc tab… ·  · 2013-10-04education in proc tabulate...

13
EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

Upload: duongduong

Post on 13-May-2018

237 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

EDUCATION IN PROC TABULATE

Georg Morsing - SAS Institute

I EDUCATION IN PROC TABULATE II

258

Page 2: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

Education in PROC TABULATE

II CONTENTS

l. Introduction

2. The TABLE statement

3. Calculations

4. Improvement of output

~. The table layout

6. The menu system

QUALIFICATIONS

Basic knowledge of:

- PROC step generally

- PROC FORMAT

- LABEL and FORMAT statements

No knowledge of:

- PROC TABULATE

·~r~Y""'..i:!r.'...r~:..:·":~~"-'.",-.:·'·"""~",,;,;,,..J.;::..->"'·>·;"·~·""-~·':;":-"·"p·":'.'<,"::"!"~·';;'':'''''"_.'''~~.:'i .... ~ .. !.~!:''_''':'··i;I_..,~' ':~"::',..r--",,:.<··,~ ", .Y':"~ ... <.,~,~:, 'r"

NECESSARY STATEMENTS

PROC TABULATE DATA= SASdataset

CLASS variable list

VAR variable list

TABLE variable/expression

II PARTITION OF VARIABLES: II

In PROC TABULATE it is necessary to characterize all variables to the SAS System:

CLASS variables:

VAR variables:

- grouped (discrete) variables

- numeric or character variables

- examples: area code year quarter

- analyze (continuous) variables

- numeric variables

- examples: income level of interest number of unemployed

Introduction

Bl '"

", :., .... :.,,>.-:.~-;.:,:::~.~.~ .. ;.;_;,;i-<.;:;;: . .w...f:-,. ,.'- - ~·'.;.:,.(''''''~~~'''~'i'~''' .... ~,..;; .. ·.·;-! • .>;j>:~J''(~·'ri-:;..·'.'·. ,(_·.,;)..·~:'!.-;...;";:..~ ... {.".<· ..... ),,~~~~~"""'"';\9:fr£¥-l~uMw6iBEID ..... ·)N-i:.>iii ... lit-H' ~f'.fti''';"v.,..

Page 3: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

~·I'~" .• .t:J'$,~,,+l.A{!.;rP:~,:,jjt _,,s'b6Ji'J.!RtiM¥!'.1 "'«" ;t~~~~_~!;e::..7'i'~-K ':-"-d:w.,o.lI~;:,' ," .~ -, .

~

PROC TABULATE; CLASS A B VAR X '{

TABLE A x '{

A

PROC TABULATE; CLASS A B VAR X '{

X

TABLE A B X '{

X

A

------

B

----

,.. ... ","~,~ '~""'

I '{

I '{

The TABLE statement

, ===> Dimension

PROC TABULATE; CLASS A B VAR X '{

TABLE A*B X

A B

PROC TABULATE; CLASS A B VAR X Y

TABLE A, X*B

The TABLE statement'

* ===> concatenating

X

* ===> Concatenating

X

B

-1-1-1-A

----

Page 4: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

The TABLE statement

options ps=42 nonumber nodate formchar='I-nn HH WU ,;

proc print data=sasuser.unemploy; title 'Number of unemployed persons in thousands in Denmark'

proc tabulate data=sasuser.unemploy;

run:

title 'Apply TABULATE to report writing'; class year quarter; var male female:

table year*quarter I male female

Number of unemployed persons in thousands in Denmark

OBS YEAR QUARTER MALE FEMALE

1 1980 1 98.700 86.833 2 1980 2 78.300 81.967 3 1980 3 83.000 87.633 4 1980 4 116.367 103.100 5 1981 1 155.100 112.300 6 1981 2 125.433 104.167 7 1981 3 113.100 102.900 8 1981 4 140.900 118.500 9 1982 1 170.367 124.533

10 1982 2 134.800 115.300 11 1982 3 122.367 115.100 12 1982 4 137.367 130.567 13 1983 1 171. 667 141. 667 14 1983 2 144.300 133.333· 15 1983 3 124.800 134.700 16 1983 4 134.633 148.033 17 1984 1 165.433 156.000 18 1984 2 126.833 143.300 19 1984 3 111. 500 138.900 20 1984 4 114.700 147.433 21 1985 1 149.800 151. 900 22 1985 2 109.833 137.767 23 1985 3 88.200 130.633 24 1985 4 87.533 135.500

,X"'.~;;';;V':d-:·:

The TABLE statement

Apply TABULATE to report writing

MALE FEMALE

SUM SUM

YEAR QUARTER

1980 1 98.70 86.83

2 78.30 81.97

3 83.00 87.63

4 116.37 103.10

1981 QUARTER

1 155.10 112.30

2 125.43 104.17;

3 113.10 102.90 ,

4 140.90 118.50 1

1982 QUARTER

124.531 1 170.37

2 134.80 115. 30 1 re 3 122.37 115.10 I

4 137.37 130.57 ,

1983 QUARTER I 1

1 171. 67 141. 67

2 144.30 133.331

3 124.80 134.70'

4 134.63 148.03

1984 QUARTER

1 165.43 156.00

2 126.83 143.30

3 111.50 138.90

4 114.70 147.43

1985 1 149.80 151. 90!

2 109.83 137.771

3 88.20 130.631

14 87.531 135.501

~,Lo·-;.>.-•. >J:~"'k"·''''''''~:''-'';':;'~'':''::'~"""",'''-;;.:M.-.;,,,::; .. -u':-~<;>~!-h~~a''';'';JiJl'~,,;;,,~,"~a~'.·.

Page 5: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

· ,~~~:-.t~~~~~·~~'!'cM!,~."{~:~.~tl~~~!~"'~ ~:&,&·jt:J~)"et"~··~~~'~''''·~,-''p-l.."','''',~\~·H·rt~'.''''::'~< " ~ ,,::..-,'">.-';'t"F~~..r~~"l/!'"i;-':-:-"'I-::-::~"?".:"':-;'-':'~l"'!"(~_'"'l~~~.t;:;,-,--·,-,-:J;"· '~~~. -~--:-: -,- -, '-

~

CALCULATIONS IN PROC TABULATE

Standard calculation: SUM

When nothing is stated, the procedure will compute the sum of the analysis variables given.

These two TABLE statements are identical:

TABLE A B , X

TABLE A B X*SUM

~ CALCULATIONS IN PROC TABULATE

Calculations

In the TABLE statement you can decide for yourself which kind of calculation you wish to execute by stating a KEYWORD.

KEYWORD can be divided into 4 groups:

1. Simple calculations

2. Additions

3. Calculation of percentages

4. statistical calculations

Simple calculations

II KEYWORDS:

N

NMISS

SUM

MEAN

MIN,

MAX

RANGE

the number of observations (- missing values)

the number of observations including missing values

the sum

the mean

the minimum

the maximum

the range between the maximum and the minimum

PROC TABULATE; CLASS A B VAR X Y

TABLE A, X*(MEAN MIN MAX)

X

MEAN I MIN I MAX

A

--------

PROC TABULATE DATA=sasuser.unemploy;

RUN;

TITLE 'Simple calculations in PROC TABULATE'; CLASS year quarter; VAR male female ;

TABLE year, male*(min mean max);

TABLE year, (male female)*(mean range)

Page 6: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

Simple calculations

Simple calculations in FRoe TABULATE

MALE

MIN MEAN MAX

YEAR

1980 78.30 94.09 116.37

1981 113.10 133.63 155.10

1982 122.37 141. 22 170.37

1983 124.80 143.85 171. 67

1984 111.50 129.62 165.43

1985 87.53 108.84 149.80

Simple calculations in PRoe TABULATE

MALE FEMALE

MEAN RANGE MEAN RANGE

YEAR

1980 94.09 38.07 89.88 21.13

1981 133.63 42.00 109.47 15.60

1982 141. 22 48.00 121. 37 15.47

1983 143.85 46.87 139.43 14.70

1984 129.62 53.93 146.41 17.10

1985 108.84 62.27 138.95 21.27

;>C!~.~""", .• ,-."?;",,, .• _.-.I"'<';: f"";:...:r ..... I:·:;"r..,!o't".u:-~."""d,',"'~ ::~....: ~;;;:"""~ ,,:y~:::'--,_.;·~,~"'·4. __ ' >:~~;!.!,"'~,,~-i-'>!-0'.:.~,-.-"'- , -"'";'t-""?-':"~'H"·"

i TOTALS IN PROe TABULATE

~ KEYWORD

ALL - calculations of a total sum, mean, eeqe

- can be placed everywhere in a TABLE statement

- may figure several times in a TABLE statement

PRoe TABULATE; eLASS A B VAR X Y ;

TABLE A ALL , X Y

x

A

ALL

Y

option ps=84; PRoe TABULATE.DATA=sasuser.unemp1oy;

TITLE 'Totals in PRoe TABULATE'; eLASS year quarter; VAR male female ;

TABLE year*(quarter ALL) ALL, (male female)*mean

RUN;

Totals

re

'-'''~··''7',:-·,,,·,;H-,'r-'-'_!.-.'!J~.~''l·''''''''';''':';;'';;':~~''''''~~·.r,,,,,,~J:.·I..":t::t..,.,_a.;;'·;;'"-·'''''$-"-,,,y;.;"l,,",,h'-!hn-''lJ?'''Mbdu.''''~~'' ...... ~~.

Page 7: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

;:~~'~~_~·f:P.';·_b'»",{\f!.-tf'i-"9,,_ ,~"",!-'::_"_'"'YK-~!",-_'~_~.'._', - ',_.' _~~:,-F:';-

Totals in PROC TABULATE

MALE

MEAN

YEAR QUARTER

1980 l' I 98.70

78.30

83.00

116.37

ALL I 94.09

1981

~ 155.10

125.43

113.10

140.90

ALL I 133.63

'" 1.1982 ~ (J) ... 170.37

134.80

122.37

137.37

ALL I 141.22

1983 0 171. 67

144.30

124,80

134.63

ALL I 143.85

1984

~ 165.43

126.83

111.50

114.70

ALL I 129.62

1985

~ 149.80

109.83

88.20

87.53

ALL I 108.84

ALL 1 125.21

Totals

FEMALE

MEAN

86.83

81.97

87.63

103.10

89.88

112.30

104.17

102.90

118.50

109.47

124.53

115.30

115.10

130.57

121.38

141.67

133.33

134.70

148.03

139.43

156.00

143.30

138.90

147.43

146.41

151. 90

137.77

130.63

135.50

138.95

124.25

Percent calculation

CALCULATION OF PERCENTAGES IN PROC TABULATE

II KEYWORD

PCTN percentage in proportion to the number of observations

PCTSUM percentage in proportion to the SUM of an analysis variable

PCTN < variable >

PCTSUM < variable*variable >

PROC TABULATE; CLASS A B VAR X Y ;

TABLE A ALL, X*( SUM PCTSUM<A ALL> )

X

SUM PCTSUM

A

------

option ps=84; PROC TABULATE

TITLE CLASS VAR

ALL

DATA=sasuser.unemploy : 'Percentages in PRoe TABULATE';

year quarter; male female ;

TABLE year*(quarter all),male*mean PCTN<QUARTER ALL>;

RUN;

Page 8: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

Percent calculation

Percentages in PROC TABUlATE

~

MALE -MEAN PCTH

YEAR .lauARTER I 1980 l' I 98.70 25.00

78.30 25.00

83.00 25.00

116.37 25.00

ALL I 94.09 100.00

1981

155.10 25.00

125.43 25.00

113.10 25.00

140.90 25.00

ALL I 133.63 100.00

1982 ~ I' l 170.37 25.00

134.80 25.00

122.37 25.00

137.37 25.00

ALL 141.22 100.00

1983 1 QUARTER

1 I 171.67 25.00

144.30 25.00

124.80 25.00

134.63 25.00

ALL 143.85 100.00

1984 I QUARTER

1 I 165. 43 1 25.00

126. 83 1 25.00

111.50 25.00

114.70 25.00

ALL 129.62 100.00

1985 !QUARTER

1 I 149.80 25.00

109.83 25.00

88.20 25.00

87.53 25.00

ALL 108.84 100.00

~~~;l"~~,~..'''':'''-'' ";"'j--;·...s;::~~w('.';t.\ ~;:.<'-_ .... '.;:e:;..(.·i-' .. );:..;v.,; .. :-,;,>-;-~ '!iW:<':'_',""''':';'~';;'.- .:,J .:ia~W;i.'-:~~i~:' . .. :".i.: - "\ •. "i"~~ -

Statistical calculations

STATISTICAL CALCULATIONS IN PROC TABULATE

KEYWORD: STD

USS

CSS

STDERR

cv

T

PRT

VAR

the standard deviation

the incorrected sum of squares

the sum of squares corrected for the mean

the standard It error If of the mean

the percentage coefficient of variation

student's t-test (population mean = 0)

the probability under the null hypothesis of obtaining an absolute value of t greater than the t value observed in this sample.

the variance

re

. -". - . ·-~_"~,:,:p:!,r;;.,."'''',·:'';·''':'-"7-~;,,,,,,,:\_~~>_,;';'~t·:>l:~·'''~-h,~~i..i2.''';:;;;~;:'""_1:liM","~i-.;.::...::'t.:t';":'i""r.l"';"l,. - 1'),,< ~~M>: "::'>'~"'" _~~~,,""l' ... ~ ... p~{: •. <r-.;~.~ ;... .. .;;;:)U~~,,"+-~\.~sov·'

Page 9: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

:-;'~~t~_!1~?":X'''':.''!:~'N'i{g'l{_~~,,_~~·~~t~~,;~:k;'-'(c', ',>-.'

'" 0'> 0'>

Improvement of output

II IMPROVEMENT OF OUTPUT ~

LABEL

FORMAT

By means of the FORMAT and the LABEL statements, all headlines in a PROC TABULATE can be changed.

Furthermore, all data in the table can be printed in a FORMAT already defined in the SAS System or in formats made by PROC FORMAT.

1. Names of variables

2. Values of variables (for CLASS variables)

3. The data part of a PROC TABULATE

4. Names of keywords

PROC TABULATE; CLASS A B VAR X Y

TABLE A. X

> A

->

X <---

SUM <---

<--

LABEL

KEY LABEL

FORMAT

PROC TABULATE; CLASS A B; VAR X Y; TABLE A. X;

Quarter

first second third fourth , ~

FORMAT A $6. LABEL X='Income l

A= 1 Quarter 1

KEYLABEL SUM= 'in 1000 DKK';

Income I in 1000 DKK

option pS=21; PROC FORMAT;

VALUE quar l='Firstl 2='Second l 3= 1 Third I 4=1 Fouth , ;

PROC TABULATE DATA=sasuser.unemploy TITLE 'Improvement of output'; CLASS year quarter;

run;

VAR male female

TABLE quarter all, (male female)*mean;

LABEL quarter='Quarter l male='Male'

female='Female ' ; KEYLABEL mean='in 1000 persons I

all='In all'; FORMAT quarter quar.;

Improvement output

Page 10: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

· :-:

Improvement of output

Improvement of output

Male Female

in 1000 in 1000 persons persons

Quarter

First 151.84 128.87

Second 119.92 119.31

Third 107.16 118.31

Fouth 121. 92 130.52

In all 125.21 124.25

:<~:o.~ ... ',_£ ...... ,.~;" ~~~"''>-lAnVii''.d . .li~/f.fl1;~";,,,;;m-''"-1''..Ii ... ~ .. :r.~4:':;'.~·'!iq.:,,::::::." .. :,,:;,,·'';;:;;·<i • ..:;:::.,.s';;:!.~H:'-~';':""r"_'<""·.or· ~-': .. " '

~ KEYLABEL PROBLEM

PROC TABULATE; CLASS A B VAR X Y i

TABLE A,X Y

Keylabel problem

> X I Y <-interest I > X Y <--+--- income

> SUM ! SUM <-procent I > SUM SUM <--+--- in DKK

( ) f-> A

--------

PROC TABULATE; CLASS A B VAR X Y

TABLE A=' I , X*MEAN=' percentaqe, Y*MEAN='in ORR'

LABEL X='interest' Y='income'

Interest ! Income

percentage! in DKK

re

< , '.,".' _,' ',.' _,',,':" :-..~~~!t;":",\.,;..h.--;;;:; . .;:-.,p.::;:-~·~,i,~-i<.'},:;';;"j,~h;..i;";::';:).;~Z;.\OiliWii ... ";""-~,,':;';'r"I_, .--;. \~. - ·"'~·t··.,.·;"·",,~~·O~~l\i~w"..i~&Ii~~"

Page 11: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

.~lt~"~~mi'>.-qph:hm~~:~~~~~"~'"''}n::+r!,J'4:.·~ " ...... ~M-!.H;:'lLt, .•.. ~". ;." ;--0".-;"''-'" h"";":;"'l~'·r~·-:::'-::'~~:,;~~~?-.''':·'~-''-~·c:~¥<,,, __ :-:-'~ :-';;::"'7"';"':;-[>';;",.,.,.\,"$."

~

TABEL LAYOUT

PROC TABULATE applies a cell format of 12.2 and 1/4 of the width of page for the row title space as a standard.

ROW TITLE SPACE

I r CELL FORMAT

I

1 A I' -I ' 1

Tabel layout

PROC TABULATE FORMAT=10.2; <------- standard format CLASS A B VAR X Y

TABLE A=' , , X*MEAN*F=5.·<--------------- format Y*F=15.2 <----------------- format

/RTS=l1;

X Y

MEAN I SUM

option ps=42; PROC FORMAT;

PICTURE komma LOW-HIGH='00000009,9 '(mult=10)

PROC TABULATE DATA=sasuser.unemploy TITLE 'Table layout';

RUN;

CLASS year quarter; VAR male female ; TABLE quarter ALL='In all' ,

male='Unemployed men' *MEAN=' l*f=10.1 female='Unemployed women' *MEAN=I '*f=komma.

/RTS=12 BOX='in 1000 persons'

FORMAT quarter quar.

Table la!out

in 1000 Unemployed Unemployed persons men women

QUARTER

First 151.8 128,8

Second 119.9 119,3

Third 107.2 118,3

Fouth 121.9 130,5

In all 125.2 124,2

Tabel layout

Page 12: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

PAGE DIMENSION

TABEL A, B , Y

I One table per group

I I Y

i I Y

Y

B I--

- --A

option ps=60; PROC TABULATE DATA=sasuser.unemploy,

TITLE 'Table layout', CLASS year quarter, VAR male female ;

A=1982

=1981

80

FORMAT quarter quar. , LABEL male='Men ' female= 'women , year='Year'; KEYLABEL all='In all',

RUN,

TABLE year , quarter all , (male female)*mean=' , / box=yage_ condense

k!i=.i.-'=.r..:.~", ..... 'r-,": "',..: ...... ~..-.... ~ __ "",;.,; .... ""'<.~ ,,>,~ 0_-~·.,.:,;·,.-.... '·.1;:_,:,:"~;..;;""," ...... ~~g"<,..~~.,,.,~ .. ,"" :.~-':::..'-~' ;;.:~'" ...-n.T>I>':' ~:-' ~.'.1'FC< ·"~·L· !r.''- ~,<,'\..'-.p.."""",."".:,..

Page d:imension Page dimension

Table layout

Year 1980 Men Women

QUARTER

First 98.70 86.83

Second 78.30 81.97

Third 83.00 87.63

Fouth 116.37 103.10

In all 94.09 89.88

~ Year 1981 Men Women

QUARTER

First 155.10 112.30

Second 125.43 104.17

Third 113.10 102.90

Fouth 140.90 118.50

In all 133.63 109.47

Year 1982 Men Women

QUARTER

First 170.37 124.53

Second 134.80 115.30

Third 122.37 115.10

Fouth 137.37 130.57

In all 141. 22 121. 37 -----_.-

" _~,n .. .:. _~:!.:::.l'';.<!'_;.~,;...'_~.h:.~:H' ... ;,i:-:T,~;,;.;.;.......,._;_ ...... :.;'"''; " • .'~,.,,-;'.7 ,', ',' ·"~-:"~";''''''.:/'':'')m~~~.h..o!~;:''','')'·i·I;';-'ip,J..;'-~& >£}WSa1:M+"il1t\f!i"%$!lJQ'r;jf?n1i?J.$..~~

Page 13: EDUCATION IN PROC TABULATE - sasCommunity PROC TAB… ·  · 2013-10-04EDUCATION IN PROC TABULATE Georg Morsing - SAS Institute I EDUCATION IN PROC TABULATE II 258

~~~~~!~""~~~t:t:-;-s.~~,,,,·:--,:?<·.';~'i,:l~'I';$t-.~"ik.-t"''''''':''h-'' :~.,.~.,-,"""<"""!~.,".~,.~~,'t.~r.:."·~,~!-"r",,-""'~~~"'J"':"_'""i"'"'"L'"1·-·'"·~!.~~~:'i·~">';'"!,~,·~~T?.t"_''':"''!l·.'":·:?~·~-.'''.-·;">-_-~'C_,-,-!~ __ -!.-;.'<!,'"·,"':,,,"'''!,,,,,~e',_, ... ">.m

Page dimension

Table layout

Year 1983 Men Women

QUARTER

First 171. 67 141. 67

Second 144.30 133.33

Third 124.80 134.70

Fouth 134.63 148.03

In all 143.85 139.43

Year 1984 Men Women I

QUARTER I !

~ First 165.43 156.00'

Second 126.83 143.30

Third 111.50 138.90

Fouth 114.70 147.43

In all 129.62 146.41

Year 1985 Men Women

QUARTER

First 149.80 151. 90

Second 109.83 137.77

Third 88.20 130.63

Fouth 87.53 135.50

In all 108.84 138.95

,': ,:;