STATISTICAL ANALYSIS SYSTEM(SAS)
PROGRAM#1 ************************** DATA TEST; INPUT SUBJECT 1-2 SEX $4 EXAM1 6-7 EXAM2 9-10 HWGRADE $12; CARDS; 10 M 80 84 A 7 M 85 89 A 4 F 90 86 B 20 M 82 85 B 25 F 94 94 A 14 F 88 84 C ; PROC MEANS DATA=TEST; RUN; PROGRAM#2 ************************** DATA TEST; INPUT SUBJECT 1-2 SEX $4 EXAM1 6-7 EXAM2 9-10 HWGRADE $12; CARDS; 10 M 80 84 A 7 M 85 89 A 4 F 90 86 B 20 M 82 85 B 25 F 94 94 A 14 F 88 84 C ; PROC MEANS DATA=TEST; VAR EXAM1 EXAM2; RUN;
PROGRAM#3 ************************** DATA TEST; INPUT SUBJECT 1-2 SEX $4 EXAM1 6-7 EXAM2 9-10 HWGRADE $12; CARDS; 10 M 80 84 A 7 M 85 89 A 4 F 90 86 B 20 M 82 85 B 25 F 94 94 A 14 F 88 84 C ; PROC MEANS DATA=TEST N MEAN STD MAXDEC = 1; VAR EXAM1 EXAM2; RUN;
PROGRAM#4 ************************** DATA TEST; INPUT SUBJECT 1-2 SEX $4 EXAM1 6-7 EXAM2 9-10 HWGRADE $12; FINAL = (EXAM1+EXAM2)/2; IF FINAL GE 0 AND FINAL LT 65 THEN GRADE = 'F'; ELSE IF FINAL GE 65 AND FINAL LT 75 THEN GRADE = 'C'; ELSE IF FINAL GE 75 AND FINAL LT 85 THEN GRADE = 'B'; ELSE IF FINAL GE 85 THEN GRADE = 'A'; CARDS; 10 M 80 84 A 7 M 85 89 A 4 F 90 86 B 20 M 82 85 B 25 F 94 94 A 14 F 88 84 C ; PROC SORT DATA = TEST; BY SUBJECT; RUN; PROC PRINT DATA = TEST; TITLE ' ROSTER IN STUDENT NUMBER ORDER'; ID SUBJECT; VAR EXAM1 EXAM2 FINAL HWGRADE GRADE; RUN; PROC MEANS DATA=TEST N MEAN STD STDERR MAXDEC = 1; TITLE 'DESCRIPTIVE STATISTICS';
VAR EXAM1 EXAM2 FINAL; RUN; PROC FREQ DATA = TEST; TABLES SEX HWGRADE GRADE; RUN; PROGRAM#5 ************************** DATA TEST; INPUT SUBJECT 1-2 SEX $4 EXAM1 6-7 EXAM2 9-10 HWGRADE $12; CARDS; 10 M 80 84 A 7 M 85 89 A 4 F 90 86 B 20 M 82 85 B 25 F 94 94 A 14 F 88 84 C ; PROC MEANS DATA=TEST N MEAN STD MAXDEC = 1; VAR EXAM1 EXAM2; RUN;
PROGRAM#6 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc univariate data=htwt normal plot; title 'More Descriptive Statistics'; var height weight; run;
PROGRAM#7 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc sort data=htwt; by gender; proc means data = htwt n mean std maxdec = 2; by gender; var height weight; run;
PROGRAM#8 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc sort data=htwt; by gender; proc means data = htwt n mean std maxdec = 2; class gender race col; var height weight; run;
PROGRAM#9 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc freq data = htwt; tables gender/ nocum nopercent; run;
PROGRAM#7 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc chart data=htwt; vbar gender; run;
PROGRAM#8 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc chart data=htwt; hbar gender; run;
PROGRAM#9 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc chart data=htwt; vbar height /levels = 6; run;
PROGRAM#10 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc chart data=htwt; vbar height /midpoints = 50 to 80 by 10; run;
PROGRAM#11 ************************** data htwt; input subject 1-2 dept $4-7 year 9-12 sales 14-17; datalines; 01 food 1989 1200 02 food 1990 1500 03 toys 1988 1700 04 food 1988 1300 05 toys 1989 2500 06 toys 1990 2400 07 toys 1990 4100 08 food 1989 5200 09 food 1990 5000 10 food 1989 4600 11 toys 1989 3000 12 food 1988 3300 13 toys 1988 3700 14 food 1989 2500 15 food 1990 2900 16 food 1990 3400 17 toys 1989 2700
18 toys 1988 1900 19 food 1989 1800 20 food 1990 2100 ; proc chart data=htwt; vbar dept; vbar sales; run;
PROGRAM#12 ************************** data htwt; input subject 1-2 dept $4-7 year 9-12 sales 14-17; datalines; 01 food 1989 1200 02 food 1990 1500 03 toys 1988 1700 04 food 1988 1300 05 toys 1989 2500 06 toys 1990 2400 07 toys 1990 4100 08 food 1989 5200 09 food 1990 5000 10 food 1989 4600 11 toys 1989 3000 12 food 1988 3300 13 toys 1988 3700 14 food 1989 2500 15 food 1990 2900 16 food 1990 3400 17 toys 1989 2700 18 toys 1988 1900 19 food 1989 1800 20 food 1990 2100 ; proc chart data=htwt; vbar sales / group = dept; run;
PROGRAM#13 ************************** data htwt; input subject 1-2 dept $4-7 year 9-12 sales 14-17; datalines; 01 food 1989 1200 02 food 1990 1500 03 toys 1988 1700 04 food 1988 1300 05 toys 1989 2500 06 toys 1990 2400 07 toys 1990 4100 08 food 1989 5200 09 food 1990 5000 10 food 1989 4600 11 toys 1989 3000 12 food 1988 3300 13 toys 1988 3700 14 food 1989 2500 15 food 1990 2900 16 food 1990 3400 17 toys 1989 2700 18 toys 1988 1900 19 food 1989 1800 20 food 1990 2100 ; proc chart data=htwt; vbar dept / group = year sumvar = sales type = sum; run; PROGRAM#14 ************************* data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc plot data=htwt; plot weight*height; run;
PROGRAM#15 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc sort data = htwt; by gender; run; proc plot data=htwt; by gender; plot weight*height; run;
PROGRAM#16 ************************** data htwt; input subject gender $ height weight; datalines; 1 m 68.5 155 2 f 61.2 99 3 f 63.0 115 4 m 70.0 205 5 m 68.6 170 6 f 65.1 125 7 m 72.4 220 ; proc plot data=htwt; plot weight*height = gender; run;
PROGRAM#17 ************************** data school; length gender $1 teacher $5; input subject gender $ teacher $ t_age pretest posttest; gain = posttest-pretest; datalines; 01 m jones 35 67 81 02 f jones 35 98 86 03 m jones 35 52 92 04 m black 42 41 74 05 f black 42 46 76 06 m smith 68 38 80 07 m smith 68 49 71 08 f smith 68 38 63 09 m hayes 23 71 72 10 f hayes 23 46 92 11 m hayes 23 70 90 12 f wong 47 49 64 13 m wong 47 50 63 ; proc means data = school n mean std maxdec = 2; class teacher; title "means for each teacher"; var pretest posttest gain; run;
PROGRAM#18 ************************** data school; length gender $1 teacher $5; input subject gender $ teacher $ t_age pretest posttest; gain = posttest-pretest; datalines; 01 m jones 35 67 81 02 f jones 35 98 86 03 m jones 35 52 92 04 m black 42 41 74 05 f black 42 46 76 06 m smith 68 38 80 07 m smith 68 49 71 08 f smith 68 38 63
09 m hayes 23 71 72 10 f hayes 23 46 92 11 m hayes 23 70 90 12 f wong 47 49 64 13 m wong 47 50 63 ; proc means data = school noprint nway; class teacher; var pretest posttest gain; output out = teachsum mean = m_pre m_post m_gain; proc print data = teachsum; run; PROGRAM#20 ************************** data quest; input id 1-3 age 4-5 gender $ 6 race $ 7 marital $ 8 educ $ 9 pres 10 arms 11 cities 12; Label age = 'age of the respondent' gender = 'gender of the respondent' marital='Marital Status' educ='Education Level' pres='President doing a good job' arms='Arms budget increases' cities='Federal Aid to Cities'; datalines; 001091111232 002452222422 003351324442 004271111121 005682132333 006651243425 ; proc freq data=quest; tables age gender race marital educ pres arms cities; run;
**************converged program*********page 66-68***************************; ***********adding value labels, variable labels****************************;
PROGRAM#21 ************************** PROC FORMAT; VALUE $gender '1'='Male' '2'='Female'; VALUE $race '1'='White' '2'='African Am.' '3'='Hispanic' '4'='Others'; VALUE $marital '1'='Single' '2'='Married' '3'='Widowed' '4'='Divorced'; VALUE $educ '1'='High School or Less' '2'='Two year College' '3'='Four Year College' '4'='Graduate Degree'; VALUE isrt 1='Strongly Disagree' 2='Disagree' 3='Neutral' 4='Agree' 5='Strongly Agree'; RUN; data quest; input id 1-3 age 4-5 gender $ 6 race $ 7 marital $ 8 educ $ 9 pres 10 arms 11 cities 12; FORMAT gender $gender. race $race. educ $educ. marital $marital. pres arms cities isrt.; Label age = 'age of the respondent' gender = 'gender of the respondent' marital='Marital Status' educ='Education Level' pres='President doing a good job' arms='Arms budget increases' cities='Federal Aid to Cities'; datalines; 001091111232 002452222422 003351324442 004271111121 005682132333 006651243425 ; proc freq data=quest; tables gender marital race educ pres arms cities; run;
*********************************************************************************; ********************page 70 Recoding data****************************************; **********************************************************************************; **********recode age variable*****except age variale this is a converged porg***TEST***** ***************************;
PROGRAM#22 ************************** PROC FORMAT; VALUE agegrp 0-20='1' 21-40 = '2' 41-60 = '3' 61-high = '4'; run; data quest; input id 1-3 age 4-5 gender $ 6 race $ 7 marital $ 8 educ $ 9 pres 10 arms 11 cities 12; FORMAT age agegrp.; datalines; 001091111232 002452222422 003351324442 004271111121 005682132333 006651243425 ; proc freq data=quest; tables age -- cities; run;
prob3_2 ********************************************** PROC FORMAT; VALUE $GENDER 'M' = 'MALE' 'F' = 'FEMALE'; VALUE PARTY 1 = 'AWAMI LEAGUE' 2 = 'BNP' 3 = 'NOT REGISTERED'; VALUE YN 0 = 'NO' 1 = 'YES'; RUN; DATA PROB3_2; INPUT ID 1-3 GENDER $ 4 PARTY 5 VOTE 6 FOREIGN 7 SPEND 8; LABEL PARTY = 'POLITICAL PARTY' VOTE = 'Did you vote?' FOREIGN = 'Do you agree with policy?' SPEND 'Should we increase spending?'; FORMAT GENDER $GENDER. PARTY PARTY. VOTE FOREIGN SPEND YN.; DATALINES; 007M1110 013F2101
017F3101 037M2101 113F1001 117M1111 ; PROC FREQ DATA = PROB3_2; TABLES GENDER -- SPEND; TABLES VOTE*(SPEND FOREIGN) / CHISQ; RUN;
Saadi 9th Batch, ISRT(ATI) ****DU****