Download presentation
Presentation is loading. Please wait.
Published byJade Stevens Modified over 8 years ago
1
Lesson 12 More SGPLOT examples Exporting data Macro variables Table Generation - PROC TABULATE Miscellaneous Topics
2
SCATTER vs SERIES vs REG vs STEP Obs trt month cd4 1 1 0 102 2 1 1 177 3 1 2 192 4 1 3 195 5 1 6 217 6 1 9 232 7 1 12 252 8 1 15 270 9 1 18 287 10 1 21 305 11 1 24 323 12 1 27 337 13 1 30 343 14 1 33 360 15 1 36 376 16 2 0 102 17 2 1 184 18 2 2 194 19 2 3 202 20 2 6 223 21 2 9 249 22 2 12 273 23 2 15 299 24 2 18 323 25 2 21 339 26 2 24 363 27 2 27 386 28 2 30 392 29 2 33 394 30 2 36 418 Want to plot mean CD4 levels over time for each of two groups.
3
* Scatter Plot for 2 group; proc sgplot; xaxis label = 'Months After Start of Therapy' values=(0 to 36 by 6); yaxis label = 'Mean CD4 Level'; title 'Mean CD4 After Start of Therapy by Treatment Type'; scatter x=month y=cd4/group=trt ; format trt trtF.; label trt = 'Treatment Group'; run; SCATTER vs SERIES vs REG vs STEP
4
* Series plot connects the points, marker option needed to plot symbols at each visit; proc sgplot; series x=month y=cd4/group=trt markers ; run;
5
* Regression plot does scatter plot and adds regression line; proc sgplot; reg x=month y=cd4/group=trt ; run;
6
* Step plot connects points with a step function; proc sgplot; step x=month y=cd4/group=trt ; run;
7
* Exporting Data; LIBNAME mylib ‘C:\SAS_Files’; DATA temp; SET mylib.sescore; KEEP ptid clinic randdate group educ wt12 sbp12 sescr12; RUN; * Export data to a comma delimited file; PROC EXPORT DATA=temp OUTFILE = 'C:\SAS_Files\se.csv' DBMS = csv REPLACE;
8
Contents of file 'se.csv' ptid,clinic,randdate,group,educ,wt12,sbp12,sescr12 A00083,A,02/05/1987,2,7,125,113,1.05 A00301,A,02/17/1987,6,9,,,1.15 A00312,A,04/08/1987,3,4,131,113,1.15 This data can easily be put into excel by clicking on the file and then saving the file as a worksheet. *export to excel directly; PROC EXPORT DATA=temp OUTFILE = 'C:\SAS_Files\se.xls' DBMS = excel ; REPLACE;
9
Moving a SAS Dataset to another computer Transfer SAS dataset directly - Easy and works on most systems - Can send as e-mail attachment Use PROC CPORT and PROC CIMPORT Works on all systems but requires you to create an xport (.xpt) file. Can transfer multiple datasets in one file.
10
Creating a SAS Export File *Run this on the your computer ; LIBNAME mylib ‘C:\SAS_Files'; FILENAME tranfile ‘C:\SAS_Files\classdata.xpt'; PROC CPORT LIB=mylib FILE=tranfile; SELECT sescore tomhsp; RUN; * Run this on the other computer ; FILENAME tranfile 'C:\My SAS Datasets\classdata.xpt'; PROC CIMPORT LIB=work FILE=tranfile; PROC CONTENTS VARNUM DATA=sescore; PROC CONTENTS VARNUM DATA=tomhsp; RUN;
11
TABLE GENERATION (dbp12 sbp12)*(N MEAN*f=8.1) GROUPALLGROUPALL
12
PROC TABULATE DATA=class.tomhsp FORMAT=8.0; CLASS group; VAR sbp12 dbp12; TABLES group ALL='Total', (dbp12 sbp12)*(N MEAN*f=8.1)/RTS=20; LABEL dbp12 = 'Diastolic BP'; LABEL sbp12 = 'Systolic BP'; LABEL group = 'RX Group'; FORMAT group fgroup.; TITLE 'Average Blood Pressure at 12-Months'; RUN; Same as PROC MEANS
13
Closer Look At TABLES Statement TABLES group ALL='Total', (dbp12 sbp12)*(N MEAN*f=8.1)/RTS=20; Statement before comma indicates row information to display Statement after comma indicates column information to display A * indicates to crosstabulate data A space indicates to concatenate data Words: For each group and the total display the N and mean of diastolic and systolic BP
14
(sex=' ')*(N ROWPCTN*f=10.1) CLINICALLCLINICALL
15
PROC TABULATE DATA=class.tomhsp FORMAT=8.; CLASS clinic sex; TABLE (clinic ALL='Total'), (sex=' ')*(N ROWPCTN*f=10.1)/RTS=15; FORMAT sex sex. clinic $clinic.; LABEL clinic = 'Clinical Center'; KEYLABEL ROWPCTN = 'Percent'; TITLE 'N and Percent Men and Women Enrolled by Center'; RUN; ODS HTML FILE = ‘mytable.html’;
16
Macro Variables and Use LIBNAME t ‘C:\SAS_Files'; %let nut = kcalbl dcholbl calcbl sodbl; %let ilist = income educ; %let options = N MEAN STDDEV; DATA temp; SET t.tomhsp (KEEP=ptid clinic &nut &ilist); PROC MEANS DATA=temp &options; VAR &nut &ilist; TITLE "PROC Means results for variables &nut and &ilist"; RUN; * Makes it easy to modify code;
17
Macro Variables Defined using %LET statement Referenced by using ¯ovarname SAS substitutes the value of macrovarname when it encounters ¯ovarname Useful for making a program easy to modify %let macrovarname = characters ;
18
Simple Macro to Shorten Code %macro change(v); dbpdif&v = dbp&v - dbpbl; sbpdif&v = sbp&v - sbpbl; choldif&v = chol&v - cholbl; glucdif&v = gluc&v - glucbl; %mend change; data temp; set temp; %change(12); %change(24); %change(36); run; Suppose I want to compute the change in 4 variables at 3 time points. Can use macro to help you. Variables: Dbp12,24,36 and dbpbl Sbp12,24,36 and sbpbl Chol12,24,36 and cholbl Gluc12,24,36 and glucbl
19
Simple Macro to Shorten Code %macro change(v); 36 %change(12); MPRINT(CHANGE): dbpdif12 = dbp12 - dbpbl; MPRINT(CHANGE): sbpdif12 = sbp12 - sbpbl; MPRINT(CHANGE): choldif12 = chol12 - cholbl; MPRINT(CHANGE): glucdif12 = gluc12 - glucbl; 36 %change(24); MPRINT(CHANGE): dbpdif24 = dbp24 - dbpbl; MPRINT(CHANGE): sbpdif24 = sbp24 - sbpbl; MPRINT(CHANGE): choldif24 = chol24 - cholbl; MPRINT(CHANGE): glucdif24 = gluc24 - glucbl; 37 %change(36); MPRINT(CHANGE): dbpdif36 = dbp36 - dbpbl; MPRINT(CHANGE): sbpdif36 = sbp36 - sbpbl; MPRINT(CHANGE): choldif36 = chol36 - cholbl; MPRINT(CHANGE): glucdif36 = gluc36 - glucbl; 38 run; SAS substitutes the value of v everywhere there is an &v
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.