Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Final Part 1 SAS - STATS 381 */
- options ls = 80 nocenter nodate ps=55 nonumber;
- title1 'MATH 381 Spring 2018';
- title2 'Final #1';
- title3 'Billy ODonnell';
- /* Establish data variable */
- data defective;
- /* Open an input file */
- infile 'C:\Users\odonnelw\Desktop\QUALITY1_S18.dat';
- /* Create an input variable */
- input defectivechips;
- /* Change title appropriate for this Q */
- title4 'Question 1';
- /* Print the output */
- proc print noobs;
- title4 'Question 1 - i';
- /* Run our FREQ procedure, using our input variable */
- proc freq;
- tables defectivechips;
- title4 'Question 1 - v';
- /* Run our means procedure to get the average number of chips per shipment */
- proc means sum mean;
- /* New data variable for next question */
- data icecream;
- infile 'C:\Users\odonnelw\Desktop\icecream1_s18.dat' firstobs = 2;
- /* Run a nested do loop to read in our data
- and establish brand classifications using if statements */
- do brand = 1 to 3;
- if brand = 1 then preference = 'Breyers ';
- else if brand = 2 then preference = 'Dreyers ';
- else preference = 'PrivateSelection';
- /* Establish age classifications */
- do age = 1 to 3;
- if age = 1 then AgeBracket = '< 21';
- else if age = 2 then AgeBracket = '21 - 45';
- else AgeBracket = ' > 45';
- /* Input variable */
- input ages @@;
- output;
- end;
- end;
- title4 'Question 2 - i';
- proc print noobs;
- title4 'Question 2 - ii';
- /* FREQ Procedure for chi sq test for independence */
- proc freq order = data;
- weight ages;
- tables age*brand/chisq expected nopercent norow nocol;
- /* New data variable for next question */
- data basketball;
- infile 'C:\Users\odonnelw\Desktop\basketballs1_s18.dat' firstobs = 2;
- /* Nested do loops for Defective v Non Defective */
- do itemClassification = 1 to 2;
- if itemClassification = 1 then entry = 'NonDefective';
- else entry = 'Defective';
- /* Secondary loop to classify by shift type */
- do shift = 1 to 2;
- if shift = 1 then shiftname = 'Day';
- else shiftname = 'Nite';
- input basketballs @@;
- output;
- end;
- end;
- title4 'Question 3 - i and ii';
- proc print noobs;
- title4 'Question 3 - iii';
- /* Chi Square test for independence using FREQ procedure */
- proc freq order = data;
- weight basketballs;
- tables itemClassification*shift/chisq expected nopercent norow nocol;
- /* New data variable for next Q */
- data ink;
- /* Our input file has both colors, a data value and a proportion,
- designate this (text value) by using $ */
- input ink_color $ observed prop;
- n = 80;
- /* Create our expected number by multiplying N by proportion expected */
- expected = n*prop;
- /* Get our ChiSquare value */
- chisq1 = (observed - expected)**2/expected;
- datalines;
- Black 28 .30
- Blue 26 .30
- Red 18 .25
- Other 8 .15
- ;
- title4 'Question 4';
- proc print noobs;
- /* Test Hypothesis */
- proc means sum noprint;
- var chisq1;
- output out = a1 sum = chisq_sum;
- proc print noobs;
- /* New data variable to hold pvalue */
- data pvalue1;
- set a1;
- pvalue = 1 - probchi(chisq_sum, 3);
- proc print noobs;
- /* New data value to do GoodnessOfFit */
- data ink2;
- input ink_color $ observed prop;
- n = 80;
- expected = n*prop;
- chisq1 = (observed - expected)**2/expected;
- datalines;
- Black 28 .30
- Blue 26 .30
- Red 18 .25
- Other 8 .15
- ;
- proc print noobs;
- title4 'Question 4';
- /* Use Univariate Procedure to get our GoodnessOfFit
- information, use estimated values because we have no
- mean and sigma */
- proc univariate;
- ods select GoodnessOfFit;
- var chisq1;
- histogram / normal(mu=est sigma = est);
- proc print noobs;
- title4 'Question 5';
- /* New data var for next Q */
- data lightbulbs;
- infile 'C:\Users\odonnelw\Desktop\LIFETEST1_S18.dat' firstobs = 2;
- input life @@;
- proc print noobs;
- /* Univariate to test for exponential distribution */
- proc univariate;
- ods select GoodnessOfFit;
- var life;
- histogram/exponential(sigma=est);
- /* New data var for next Q */
- data exams;
- infile 'C:\Users\odonnelw\Desktop\COMPLETION1_S18.dat' firstobs = 2;
- input completion @@;
- title4 'Question 6';
- proc print noobs;
- /* Univariate to test for normal distribution using mean = 95 minutes
- and sigma = 15 minutes */
- proc univariate;
- ods select GoodnessOfFit;
- var completion;
- histogram/normal(mu=95 sigma=15);
- run; quit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement