1 / 24

Lesson 12

Lesson 12. Topics. Macro example Exporting data Character Functions Background to final assignment. ---------------------------------------------------------------------- | | Diastolic BP at 12-Months |

lcornell
Download Presentation

Lesson 12

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 12 Topics • Macro example • Exporting data • Character Functions • Background to final assignment

  2. -------------------------------------------------------------------------------------------------------------------------------------------- | | Diastolic BP at 12-Months | | |---------------------------------------| | | N | Mean | Std | Min | Max | |----------------------------+-------+-------+-------+-------+-------| |Study Group (1-6) | | | | | | |1 | 15| 77.8| 9.3| 68.0| 94.0| |2 | 17| 81.7| 7.1| 72.0| 100.0| |3 | 14| 78.1| 7.6| 67.0| 90.0| |4 | 14| 77.7| 6.0| 66.0| 89.0| |5 | 13| 79.6| 8.5| 66.0| 99.0| |6 | 19| 79.6| 7.3| 64.0| 95.0| |All | 92| 79.2| 7.6| 64.0| 100.0| ---------------------------------------------------------------------- proc tabulate data=tomhs noseps; class group; var dbp12; table (group all), (dbp12)*(n*f=7.0 mean*f=7.1 std*f=7.1 min*f=7.1 max*f=7.1)/rts=30; run;

  3. MACRO BRKSPSS: Creates tabulate table for each var in dlist by group %macro brkspss (grp,dlist,data=_last_,dec=3,all=all); %do I = 1 %to 100; %let depvar = %scan(&dlist,&i); %let %length(&depvar) = 0 %then %goto done; proc tabulate data=&data noseps; class &grp; var &depvar; table (&grp &all), (&depvar)*(n*f=7.0 mean*f=7.&dec std*f=7.&dec min*f=7.&dec max*f=7.&dec)/rts=30; run; %end; %done: %mend brkspss; %brkspss(group,dbp12 sbp12 chol12);

  4. MACRO BRKSPSS: Creates tabulate table for each var by group LIBNAME t '~/PH6420/2017/Data/'; DATA stat; set t.tomhs; RUN; * Example calls; %brkspss(group,dbp12 sbp12 chol12); %brkspss(group,dbp12 sbp12 chol12, dec=1); * Just 1-decimal; %brkspss(group,dbp12 sbp12 chol12, all=); * No totals;

  5. Output from last call: First 2 variables. ---------------------------------------------------------------------- | | Diastolic BP at 12-Months | | |---------------------------------------| | | N | Mean | Std | Min | Max | |----------------------------+-------+-------+-------+-------+-------| |Study Group (1-6) | | | | | | |1 | 15| 77.800| 9.314| 68.000| 94.000| |2 | 17| 81.706| 7.078| 72.000|100.000| |3 | 14| 78.071| 7.580| 67.000| 90.000| |4 | 14| 77.714| 5.954| 66.000| 89.000| |5 | 13| 79.615| 8.540| 66.000| 99.000| |6 | 19| 79.579| 7.313| 64.000| 95.000| ---------------------------------------------------------------------- ---------------------------------------------------------------------- | | Systolic BP at 12-Months | | |---------------------------------------| | | N | Mean | Std | Min | Max | |----------------------------+-------+-------+-------+-------+-------| |Study Group (1-6) | | | | | | |1 | 15|120.200| 12.537| 93.000|141.000| |2 | 17|124.118| 11.280|108.000|142.000| |3 | 14|117.429| 9.436|104.000|135.000| |4 | 14|127.571| 11.876|112.000|149.000| |5 | 13|123.154| 18.348| 94.000|158.000| |6 | 19|129.895| 12.987|105.000|154.000| ----------------------------------------------------------------------

  6. Where to put macro? • At beginning of program before you call it %macro brkspss(parameters); … macro code %mend brkspss; data tomhs; set t.tomhs; run; %brkspss (group, dbp12 sbp12, data=tomhs); • Save as separate sas file and %include file on top of program. %include ‘/folderpath/brkspss.sas’; %brkspss(group, dbp12 sbp12, data=tomhs);

  7. %condesf macro: Very Useful Condescriptive of: tomhscv (Obs=902, Nvar=15 Created: 27NOV17 15:52) Seq Name T Format Variable Label N Mean Std Dev Minimun Maximum ----------------------------------------------------------------------------------------------------------------------------- 1 ptid C6 Patient ID 902 A00001 D02136 2 group N8 Study Group (1-6) 902 3.788248 1.787413 1 6 3 age N8 Age (y) at Randomization 902 54.77273 6.40394 44 69 4 sex N8 1=Male 2=Female 902 1.382483 0.486263 1 2 5 eversmk N8 Ever Smoke Cigarettes (1=Y, 2=N) 899 1.532814 0.4992 1 2 6 nowsmk N8 Now Smoke Cigarettes (1=Y, 2=N) 424 1.768868 0.422055 1 2 7 sbpbl N8 Systolic BP at Baseline 902 140.3636 12.4446 113.5 190 8 sbp12 N8 Systolic BP at 12-Months 848 124.1002 15.18918 87 187 9 cholbl N8 Total Cholesterol at Baseline 900 228.2511 38.41697 113 357 10 chol12 N8 Total Cholesterol at 12-Months 849 220.8386 38.86243 111 456 11 hdlbl N8 HDL Cholesterol at Baseline 900 43.61222 11.61247 17 97 12 hdl12 N8 HDL Cholesterol at 12 Months 849 45.49234 12.10597 18 102 13 glucosbl N8 Blood Glucose at Baseline 902 100.9246 15.61577 67 206 14 glucos12 N8 Blood Glucose at 12 Months 845 98.67219 16.85603 68 294 15 cvd N8 Cardiovascular Event (1=yes,2=no) 902 1.875831 0.329957 1 2

  8. Steps to Using %condesf • Download the macro from class website • Place macro in folder • Use %include to make the macro available • Call the macro

  9. Using %condesf libname t ‘/folders/myfolders/’; %include ‘/folders/myfolders/condesf.sas’; * if using SAS University edition; %condesf(t.tomhscv,folder=/folders/myfolders/); * Generates two files: tomhscv.condes and tomhs.pdf;

  10. * Exporting Data; LIBNAME t ‘C:\SAS_Files’; DATA tomhs; SET t.tomhs; KEEP ptid clinic randdate group educ wt12 sbp12; RUN; * Export data to a comma delimited file; PROCEXPORT DATA=tomhs OUTFILE = 'C:\SAS_Files\tomhs.csv' DBMS = csv REPLACE;

  11. Contents of file ‘tomhs.csv' ptid,clinic,randdate,group,educ,wt12,sbp12 A00083,A,02/05/1987,2,7,125,113 A00301,A,02/17/1987,6,9,,, A00312,A,04/08/1987,3,4,131,113 This file can be read by other software program, e.g. excel or R.

  12. 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.

  13. Creating a SAS Export File • * Run this on the your computer ; • LIBNAME mylib ‘C:\SAS_Files'; • FILENAME tranfile ‘C:\SAS_Files\classdata.xpt'; • PROCCPORTLIB=mylib FILE=tranfile; • SELECT sescore tomhs; • RUN; * Run this on the other computer ; FILENAME tranfile 'C:\My SAS Datasets\classdata.xpt'; PROCCIMPORT LIB=work FILE=tranfile; PROCCONTENTSVARNUMDATA=sescore; PROCCONTENTSVARNUMDATA=tomhs; RUN;

  14. * Character functions; Start with 3 names all in caps: fname = GREGORY lname = GRANDITS mi = A Create a new variable fullname = Gregory A. Grandits

  15. Functions/Operators SUBSTR Takes a subset of characters from a character variable LOWCASE Changes characters to lower case (also UPCASE and PROPCASE) || Concatenates variables or strings var1 = 'abc'; var2 = 'def'; var3 = var1||var2; var3 has value 'abcdef‘ CAT (CATX) Functions that concatenate vars/strings SCAN Picks off “words” from a char variable Section 3.3 LSB

  16. DATA names; INFILE DATALINES DSD; INFORMAT fname $20. lname $20. mi $1. ; INPUT lname fname mi ; LENGTH fnamemix $20. lnamemix $20. fullname $44.; fnamemix = PROPCASE(fname); lnamemix = PROPCASE(lname); miperiod = CAT(mi,'.'); fullname = CATX(' ',fnamemix,miperiod,lnamemix); DATALINES; GRANDITS, GREGORY, A SIU, YI, W ; Obs fnamemix lnamemix miperiod fullname 1 Gregory Grandits A. Gregory A. Grandits 2 Yi Siu W. Yi W. Siu

  17. * Start with one variable for full name but wish to create separate variables for each. Use the SCAN function ; DATA names; INFILE DATALINES DSD; INFORMAT fullname $44.; INPUT fullname ; LENGTH fname $20. lname $20. mi $2.; fname = SCAN(fullname,1); *Take 1st word; mi = SCAN(fullname,2,' '); *Take 2nd word; lname = SCAN(fullname,3); *Take 3rd word; DATALINES; Gregory A. Grandits Yi W. Siu ;

  18. ; PROCPRINTDATA=names; VAR fullname fname mi lname; TITLE'Original Variable and new variables'; RUN; Obs fullname fname mi lname 1 Gregory A. Grandits Gregory A. Grandits 2 Yi W. Siu Yi W. Siu

  19. Background to Final Assignment • Assessing individual risk of CVD is important to determining treatment options • Age, blood pressure, cholesterol, smoking, and diabetes are risk factors for CVD • The Framingham study has baseline RF and long-term follow-up for CVD that allows estimating long-term risk based on baseline RF

  20. Framingham Equation • Uses baseline smoking, systolic BP, total cholesterol, HDL-C, and diabetes status to quantify risk of CVD • Uses Cox-regression (similar to logistic regression) with above RF in model to estimate CVD risk. • Plug in above RF values into formula to estimate probability of CVD in 10-years.

  21. Framingham Equation(Formula for Women) 2.33 * log of age + 1.21 * log of total cholesterol - 0.71 * log HDL cholesterol + 2.76 * log systolic BP + 0.53 * smoking (0 or 1) + 0.69 * diabetes (0 or 1) Compute total score for individual Average total score = 26.19

  22. Framingham Equations(Formula for Women) difference= (total score for person – average score) P = 1 – 0.95exp(difference) Simple example: If total score = average score P = 1 – 0.95exp(0) = 1 – 0.95 = 0.05

  23. Framingham Equation(Example for Women) age = 61 total cholesterol = 180 HDL-C = 47 Systolic BP = 124 Current smoker (1) Not diabetic (0) Score = 2.33 * log(61) + 1.21 * log(180) – 0.71 * log(47) + 2.76 * log(124) + 0.53 * 1 + 0.69 * 0 = 26.97 p = 1-0.95exp(26.97-26.19) = 0.1048

  24. SAS Functions Needed • log = natural log • exp = exponentiation • ** = raised to a power Score = 2.33*log(age) + … ; Risk = 1 – 0.95**exp(score – average score);

More Related