1 / 22

Lesson 4 Overview

Lesson 4 Overview. Descriptive Procedures Procedures FREQ, CORR, REG, SGPLOT Comment and Option Statements Program 4 in course notes LSB: See syllabus LSB: Chapter 11 – Debugging Programs. Program 4. DATA weight; INFILE ‘C:SAS_Filestomhs.dat' ; INPUT @ 1 ptid $10.

ziven
Download Presentation

Lesson 4 Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lesson 4 Overview • Descriptive Procedures • Procedures FREQ, CORR, REG, SGPLOT • Comment and Option Statements • Program 4 in course notes • LSB: See syllabus • LSB: Chapter 11 – Debugging Programs

  2. Program 4 DATA weight; INFILE‘C:\SAS_Files\tomhs.dat' ; INPUT @1 ptid $10. @12 clinic $1. @27 age 2. @30 sex 1. @58 height 4. @85 weight 5. @140 cholbl 3. ; bmi = (weight*703.0768)/(height*height); RUN;

  3. PROCFREQDATA=weight; TABLES clinic sex ; TITLE'Frequency Distribution of Clinical Center and Gender'; RUN; Frequency Distribution of Clinical Center and Gender The FREQ Procedure Cumulative Cumulative clinic Frequency Percent Frequency Percent ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ A 18 18.00 18 18.00 B 29 29.00 47 47.00 C 36 36.00 83 83.00 D 17 17.00 100 100.00 Cumulative Cumulative sex Frequency Percent Frequency Percent ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 1 73 73.00 73 73.00 2 27 27.00 100 100.00

  4. PROCFREQDATA=weight; TABLES clinic/ NOCUM ; TITLE'Frequency Distribution of Clinical Center '; TITLE2'(No Cumulative Percentages) '; RUN; Frequency Distribution of Clinical Center (No Cumulative Percentages) The FREQ Procedure clinic Frequency Percent ------------------------------- A 18 18.00 B 29 29.00 C 36 36.00 D 17 17.00

  5. *2-Way Frequency Tables ; PROCFREQDATA=weight; TABLES sex*clinic ; TITLE'Cross Tabulation of Clinical Center and Sex'; RUN; *Adding a two-way plot ; PROCFREQDATA=weight; TABLES sex*clinic/ PLOTS=FREQPLOT(TWOWAY=GROUPHORIZONTAL); RUN;

  6. Cross Tabulation of Clinical Center and Sex The FREQ Procedure Table of sex by clinic sex clinic Frequency| Percent | Row Pct | Col Pct |A |B |C |D | Total ---------+--------+--------+--------+--------+ 1 | 12 | 20 | 30 | 11 | 73 | 12.00 | 20.00 | 30.00 | 11.00 | 73.00 | 16.44 | 27.40 | 41.10 | 15.07 | | 66.67 | 68.97 | 83.33 | 64.71 | ---------+--------+--------+--------+--------+ 2 | 6 | 9 | 6 | 6 | 27 | 6.00 | 9.00 | 6.00 | 6.00 | 27.00 | 22.22 | 33.33 | 22.22 | 22.22 | | 33.33 | 31.03 | 16.67 | 35.29 | ---------+--------+--------+--------+--------+ Total 18 29 36 17 100 18.00 29.00 36.00 17.00 100.00 Percent men in clinic A

  7. *Getting only the counts ; PROCFREQDATA=weight; TABLES sex*clinic / nopercent norow nocol; RUN; sex clinic Frequency|A |B |C |D Total ---------+--------+--------+--------+--------+ 1 | 12 | 20 | 30 | 11 | 73 ---------+--------+--------+--------+--------+ 2 | 6 | 9 | 6 | 6 | 27 ---------+--------+--------+--------+--------+ Total 18 29 36 17 100

  8. OTHER USEFUL TABLE OPTIONS • CHISQ – performs chi-square analyses for 2-way tables • MISSING – includes missing data as a separate category • LIST – makes condensed table (useful when looking at 3-way or higher tables)

  9. * Using PROC SGPLOT for bar charts; ODSGRAPHICS /WIDTH=300px ; PROCSGPLOT; VBAR clinic; TITLE"Vertical Bar Chart of Clinical Center"; LABEL clinic = "Clinical Center"; Plot can be imbedded into an HTML document or kept as a separate file. The file can be inserted in Office documents.

  10. * Same plot displayed horizontally; PROCSGPLOT; HBAR clinic; TITLE“Horizontal Bar Chart of Clinical Center"; LABEL clinic = "Clinical Center";

  11. * DATALABEL puts values on top of bar; PROCSGPLOT; YAXISLABEL = "Mean Cholesterol" VALUES = (0to300by50); VBAR clinic/RESPONSE=cholbl STAT=MEAN DATALABEL ; TITLE'Mean Cholesterol by Clinical Center'; LABEL clinic = "Clinical Center"; RUN;

  12. * Using SGPLOT to make regression plot; PROCSGPLOTDATA=weight; YAXISLABEL = "Body Mass Index (BMI)" ; XAXISLABEL = "Age (y)" ; REGX=age Y=bmi/CLM; WHERE sex = 2; TITLE'Plot of BMI and Age for Women'; RUN;

  13. PROCCORRDATA=weight; VAR bmi age; WHERE gender = 2; TITLE'Correlation of BMI and Age for Women'; RUN; Correlation Coefficient P-value testing if correlation is significantly different from zero Pearson Correlation Coefficients, N = 27 Prob > |r| under H0: Rho=0 bmi age bmi 1.00000 -0.44397 0.0203 age -0.44397 1.00000 0.0203

  14. ODSGRAPHICS ; PROCREGDATA=weight ; MODEL bmi=age; WHERE gender = 2; TITLE'Simple Linear Regression'; RUN; Partial Output Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > |t| Intercept 1 43.61312 6.40001 6.81 <.0001 age 1 -0.28964 0.11710 -2.47 0.0205 Regression equation: bmi = 43.61 - 0.29*age *Note: many options for plotting within proc reg. ODS graphics on will produce many plots by default.

  15. Fit plot from PROC REG

  16. Using Comments in Program • Two Purposes • Documenting your program • Temporarily delete part of a program • See page 3 LSB

  17. Examples of Comment Code * Run proc univariate for variable BMI; *---------------------------------------------------------------------* High resolution graphs can also be produced. The following makes a plot of a histogram with the best fit normal curve and summary statistics. *---------------------------------------------------------------------*; PROCUNIVARIATEDATA = weight PLOT ; * ID ptid ; VAR bmi; PROCUNIVARIATEDATA = weight /*PLOT*/; VAR bmi;

  18. Temporarily Removing Code: Do not want to produce histogram but may want to run it at another time PROCUNIVARIATEDATA = weight; VAR bmi; /* HISTOGRAM bmi / NORMAL MIDPOINTS=20 to 40 by 2; INSET N = 'N' (5.0) MEAN = 'Mean' (5.1) STD = 'Sdev' (5.1) MIN = 'Min' (5.1) MAX = 'Max' (5.1)/ POS=lm HEADER='Summary Statistics'; */ LABEL bmi = 'Body Mass Index (kg/m2)'; TITLE'Histogram of BMI'; RUN;

  19. What is wrong with this program ? * This is my first SAS program DATA bp; INFILE ... (more lines)

  20. Option Statement OPTION NOCENTER LINESIZE = 78; OPTION NODATE NONUMBER; Many, many options (run PROC OPTIONS) Usually put at top of program Can put in autoexec.sas so they will always be in effect.

More Related