libname sasin 'h:\PRG\PRG9\unscored'; libname sasout 'h:\PRG\PRG9\scored'; data dc9an1; set sasin.dc9an1; data nc9an1; set sasin.nc9an1; data pc9an1; set sasin.pc9an1; data sc9an1; set sasin.sc9an1; data comb; set dc9an1 nc9an1 pc9an1 sc9an1; proc sort; by cohort site tcid; libname allkey 'h:\allkey'; data allkey1; set allkey.allkey1; proc sort; by cohort site tcid; data merged; merge comb allkey1; by cohort site tcid; data c9ansc1; set merged; run; **Enter year of data collection**; %let yr = 9; data scoredPRG&yr.; set c9ansc1; if c9an1=S then c9an1=.; if c9an2=S then c9an2=.; if c9an3=S then c9an3=.; if c9an4=S then c9an4=.; if c9an5=S then c9an5=.; if c9an6=S then c9an6=.; run; %let INDATA = scoredPRG&yr.; ** The macro "linmean" creates derived variables which are means of input ** ** scale items. In the case of missisng input items, the output variable ** ** is defined to be missing if half or more of the input items are ** ** missing. Otherwise, missing input items are replaced with the mean of ** ** the nonmissing items. The macro call to linmean specifies the input ** ** items as a string "var_list" of variable names, and specifies the ** ** label and name of the output variable as "var_name" and "var_labl" ** ** respectively. **; %macro linmean; data &INDATA; set &INDATA; label &var_name="&var_labl"; array sumvars {*} &var_list; if n(of sumvars(*))>=.5*dim(sumvars) then &var_name=mean(of sumvars(*)); proc sort; by site tcid; run; %mend linmean; data sasout.scoredPRG&yr.; set scoredPRG&yr.; proc sort; by cohort site tcid; run; data sasout.scoredPRG&yr.; set scoredPRG&yr.; keep site tcid cohort C&yr.an1 C&yr.an2 C&yr.an3 C&yr.an4 C&yr.an5 C&yr.an6 treatmnt norm; run; proc contents; run; proc freq; tables (C&yr.an1 C&yr.an2 C&yr.an3 C&yr.an4 C&yr.an5 C&yr.an6); run; proc freq; where norm='N'; tables (C&yr.an1 C&yr.an2 C&yr.an3 C&yr.an4 C&yr.an5 C&yr.an6); run; proc freq; where treatmnt='C'; tables (C&yr.an1 C&yr.an2 C&yr.an3 C&yr.an4 C&yr.an5 C&yr.an6); run;