************************************ Intro to SAS Example Code ***********************************; *Let's create some study subjects; DATA EXAMPLE; DO ZSUBJECTID=8101 TO 8180; OUTPUT; END; RUN; *Now, let's assign genders. Let's assume 50% for each gender, assigned by a uniform RV. We will use <.5 is 0, ge .5 is 1, and we'll use a seed value of 10; DATA EXAMPLE; SET EXAMPLE; RANDSEX=RANUNI(10); IF RANDSEX LT .5 THEN GENDER=0; ELSE IF RANDSEX GE .5 THEN GENDER=1; ELSE RANDSEX=9; *this is a safeguard... shouldn't see any 9s! ; RUN; *If we want, we can check to see how "equal" this really is; PROC FREQ DATA=EXAMPLE; TABLE GENDER; RUN; *Now, let's create 3 blood pressure measurements for each subject (say for three visits); *Let's make the SBP measurements normal with mean 120, std dev 10, seeds 5,7, and 9, respectively; DATA EXAMPLE; SET EXAMPLE; SBP1=120+10*rannor(5); SBP2=120+10*rannor(7); SBP3=120+10*rannor(9); RUN; *Let's make a dataset for just females (0 gender); DATA FEMALES; SET EXAMPLE; WHERE GENDER=0; RUN; *The FEMALES dataset is in short format. Let's convert it to long; DATA FEMALELONG; SET FEMALES; ARRAY BP_ARRAY[3] SBP1-SBP3; DO VISIT = 1 TO 3; SBP=BP_ARRAY[VISIT]; OUTPUT; END; KEEP ZSUBJECTID GENDER VISIT SBP; RUN; *Let's create a library to hold the original example dataset and formats; LIBNAME KYRA "C:\Users\Kyra\Documents\MUSC\Spring 12"; *Now let's assign a format for gender; PROC FORMAT LIBRARY=KYRA; *Creates permanent formats; VALUE fmtgender 0='FEMALE' 1='MALE'; RUN; options fmtsearch=(KYRA); *Tells SAS where to look for the formats; *Let's permanently save our dataset to this library; DATA KYRA.EXAMPLE; SET EXAMPLE; DROP RANDSEX; *We don't care how the gender was assigned now; FORMAT GENDER fmtgender.; RUN; *Can print the dataset (with labels now); PROC PRINT DATA=KYRA.EXAMPLE NOOBS ; RUN;