Advertisement
Guest User

Untitled

a guest
May 14th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 4.15 KB | None | 0 0
  1. /* Final Part 1 SAS - STATS 381 */
  2. options ls = 80 nocenter nodate ps=55 nonumber;
  3. title1 'MATH 381 Spring 2018';
  4. title2 'Final #1';
  5. title3 'Billy ODonnell';
  6.  
  7. /* Establish data variable */
  8. data defective;
  9. /* Open an input file */
  10. infile 'C:\Users\odonnelw\Desktop\QUALITY1_S18.dat';
  11. /* Create an input variable */
  12. input defectivechips;
  13. /* Change title appropriate for this Q */
  14. title4 'Question 1';
  15. /* Print the output */
  16. proc print noobs;
  17. title4 'Question 1 - i';
  18. /* Run our FREQ procedure, using our input variable */
  19. proc freq;
  20.     tables defectivechips;
  21. title4 'Question 1 - v';
  22. /* Run our means procedure to get the average number of chips per shipment */
  23. proc means sum mean;
  24.  
  25. /* New data variable for next question */
  26. data icecream;
  27. infile 'C:\Users\odonnelw\Desktop\icecream1_s18.dat' firstobs = 2;
  28.  
  29. /* Run a nested do loop to read in our data
  30. and establish brand classifications using if statements */
  31. do brand = 1 to 3;
  32. if brand = 1 then preference =      'Breyers ';
  33. else if brand = 2 then preference = 'Dreyers ';
  34. else preference = 'PrivateSelection';
  35.  
  36. /* Establish age classifications */
  37. do age = 1 to 3;
  38.     if age = 1 then AgeBracket = '< 21';
  39.     else if age = 2 then AgeBracket = '21 - 45';
  40.     else AgeBracket = ' > 45';
  41. /* Input variable */
  42. input ages @@;
  43. output;
  44. end;
  45. end;
  46. title4 'Question 2 - i';
  47. proc print noobs;
  48.  
  49. title4 'Question 2 - ii';
  50. /* FREQ Procedure for chi sq test for independence */
  51. proc freq order = data;
  52.     weight ages;
  53.     tables age*brand/chisq expected nopercent norow nocol;
  54.  
  55. /* New data variable for next question */
  56. data basketball;
  57. infile 'C:\Users\odonnelw\Desktop\basketballs1_s18.dat' firstobs = 2;
  58.  
  59. /* Nested do loops for Defective v Non Defective */
  60. do itemClassification = 1 to 2;
  61. if itemClassification = 1 then entry = 'NonDefective';
  62. else entry = 'Defective';
  63.  
  64. /* Secondary loop to classify by shift type */
  65. do shift = 1 to 2;
  66.     if shift = 1 then shiftname = 'Day';
  67.     else shiftname = 'Nite';
  68. input basketballs @@;
  69. output;
  70. end;
  71. end;
  72. title4 'Question 3 - i and ii';
  73. proc print noobs;
  74. title4 'Question 3 - iii';
  75. /* Chi Square test for independence using FREQ procedure */
  76. proc freq order = data;
  77.     weight basketballs;
  78.     tables itemClassification*shift/chisq expected nopercent norow nocol;
  79.  
  80. /* New data variable for next Q */
  81. data ink;
  82. /* Our input file has both colors, a data value and a proportion,
  83. designate this (text value) by using $ */
  84. input ink_color $ observed prop;
  85. n = 80;
  86. /* Create our expected number by multiplying N by proportion expected */
  87. expected = n*prop;
  88. /* Get our ChiSquare value */
  89. chisq1 = (observed - expected)**2/expected;
  90. datalines;
  91. Black 28 .30
  92. Blue 26 .30
  93. Red 18 .25
  94. Other 8 .15
  95. ;
  96. title4 'Question 4';
  97. proc print noobs;
  98. /* Test Hypothesis */
  99. proc means sum noprint;
  100.     var chisq1;
  101.     output out = a1 sum = chisq_sum;
  102. proc print noobs;
  103. /* New data variable to hold pvalue */
  104. data pvalue1;
  105. set a1;
  106. pvalue = 1 - probchi(chisq_sum, 3);
  107. proc print noobs;
  108.  
  109. /* New data value to do GoodnessOfFit */
  110. data ink2;
  111. input ink_color $ observed prop;
  112. n = 80;
  113. expected = n*prop;
  114. chisq1 = (observed - expected)**2/expected;
  115. datalines;
  116. Black 28 .30
  117. Blue 26 .30
  118. Red 18 .25
  119. Other 8 .15
  120. ;
  121. proc print noobs;
  122. title4 'Question 4';
  123. /* Use Univariate Procedure to get our GoodnessOfFit
  124. information, use estimated values because we have no
  125. mean and sigma */
  126. proc univariate;
  127.     ods select GoodnessOfFit;
  128.     var chisq1;
  129.     histogram / normal(mu=est sigma = est);
  130. proc print noobs;
  131.  
  132. title4 'Question 5';
  133. /* New data var for next Q */
  134. data lightbulbs;
  135. infile 'C:\Users\odonnelw\Desktop\LIFETEST1_S18.dat' firstobs = 2;
  136. input life @@;
  137. proc print noobs;
  138. /* Univariate to test for exponential distribution */
  139. proc univariate;
  140.     ods select GoodnessOfFit;
  141.     var life;
  142.     histogram/exponential(sigma=est);
  143.  
  144.  
  145. /* New data var for next Q */
  146. data exams;
  147. infile 'C:\Users\odonnelw\Desktop\COMPLETION1_S18.dat' firstobs = 2;
  148. input completion @@;
  149. title4 'Question 6';
  150. proc print noobs;
  151. /* Univariate to test for normal distribution using mean = 95 minutes
  152. and sigma = 15 minutes */
  153. proc univariate;
  154.     ods select GoodnessOfFit;
  155.     var completion;
  156.     histogram/normal(mu=95 sigma=15);
  157. run; quit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement