*********************************************; * f=sasmanual\clinq_manip.sas *; * *; * Clinical data set questions: *; * IV. Data Manipulation (new variables) *; *********************************************; options linesize=min; libname mydir 'c:\My Documents\My SAS Files\sasmanual\data'; proc format; value ratef low-69 = '1' 70-85 = '2' 86-high= '3'; value $ratel '1' = '<70' '2' = '70-85' '3' = '86 and over'; run; data clin; set mydir.clinical; /* QUESTION 1 */ bpratio = round((sbp/dbp),0.1); /* QUESTION 2 */ prim_sub = substr(prim_dx,2,1); /* QUESTION 3 */ bpnorm = (65<=dbp<=90) and (100<=sbp<=140); /* QUESTION 4 */ rateput=put(hr,ratef.); if hr<70 then rateif='1'; else if 70<=hr<=85 then rateif='2'; else if hr>85 then rateif='3'; run; proc freq data=clin; tables bpratio; title1 'The simulated clinical data from the SAS manual'; title2 'Question 1 - Create blood pressure ratio variable'; run; proc freq data=clin; tables prim_sub * prim_dx /list missing; title2 'Question 2 - Create new variable from prim_dx'; run; proc freq data=clin; tables bpnorm * sbp * dbp /list missing; title2 'Question 3 - Create new 1/0 blood pressure variable'; run; proc freq data=clin; tables rateif rateput; title2 'Question 4 - Create new grouped variable for bp'; format rateif rateput $ratel.; run;