*getting baseline data with manual input; data baseline; input id gender $ age pre trt; datalines; 1 male 45 200 1 2 male 22 130 1 3 male . 240 0 4 male 65 190 1 5 male 80 200 0 6 female 54 160 1 7 female 27 135 0 8 female 34 180 0 9 female 67 165 1 10 female 45 200 0 ; run; *getting followup data with proc import; *you can also go to file -> import data, and use the wizard; PROC IMPORT OUT= WORK.Followup1 DATAFILE= "I:\School\Computing\Teaching\intro_data1.csv" DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; RUN; PROC IMPORT OUT= WORK.Followup2 DATAFILE= "I:\School\Computing\Teaching\intro_data2.csv" DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; RUN; *stacking datasets with set; data followup3; set followup1 followup2; run; *preparing to merge; *creating unique identifier; data followup4; set followup3; id=subj; post=bp; drop subj bp; run; *pre-sorting; proc sort data=baseline; by id; run; proc sort data=followup4; by id; run; *merging and calculating change score; data together; merge baseline followup4; by id; change=post-pre; *keep id gender age change trt; run; *always check your data to make sure the merge was done correctly; *sometimes, it may be helpful to comment out your keep statement at first; data categorical; set together; if age not= . then do; if age <40 then cat_age=1; else if age < 60 then cat_age = 2; else cat_age=3; end; run; *note how I handled missingness with this do loop; *now for some procs; *checking randomization with proc freq; proc freq data=categorical; table trt*(gender cat_age)/missing; run; *sorting for means procedure; proc sort data=categorical; by trt; run; *descriptives for all data; proc means data=categorical; by trt; var change; run; *descptives for cat_age=2; proc means data=categorical; where cat_age=2; by trt; var change; run; *formatting; proc format; value trt 0="placebo" 1="active trt"; run; data pretty; set categorical; format trt trt.; run; *now, the following output will be more straightforward; proc means data=pretty; by trt; var change; run; *creating a library; libname Kat "I:\\School\Computing\Teaching"; *formatting and saving data; proc format library=Kat; value trt 0="placebo" 1="active trt"; run; data kat.final; set categorical; format trt trt.; run;