data survey; infile 'survey.txt'; input id q1 q2 q3a q3b q3c q4 $; if q3a eq . and ( q3b ne . or q3c ne . ) then q3a = 0; if q3b eq . and ( q3a ne . or q3c ne . ) then q3b = 0; if q3c eq . and ( q3a ne . or q3b ne . ) then q3c = 0; if q3b eq . and q3a eq . and q3c eq . and q3c eq . and q4 eq " " then delete; if q3a ne . then qtot = q3a ; else if q4 eq 'a' then qtot = 100; else if q4 eq 'b' or q4 eq 'c' then qtot = 0; else if q4 eq 'd' then qtot = .; data infosur; infile 'data'; input i group id x state $; proc sort data=survey; by id; proc sort data=infosur; by id; data survey; merge survey infosur; by id; data survey; set survey; ntot = qtot * x /100; proc print; proc freq; tables q1 q2 q3a q3b q3c q4 qtot ntot; proc means sum mean; var q1 q2 q3a q3b q3c qtot ntot x; run;