data survey; input State $ Answer $ @@; datalines; NY YES NY YES NY YES NY YES NY YES NY YES NY NO NY NO NY NO NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC YES NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO NC NO PA YES PA YES PA YES PA YES PA YES PA YES PA YES PA YES PA YES PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO PA NO VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA YES VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO VA NO ;
proc sql; title1 'Survey Responses'; select survey.Answer, State, count(State) as Count, calculated Count/Subtotal as Percent format=percent8.2 from survey, (select Answer, count(*) as Subtotal from survey group by Answer) as survey2 where survey.Answer=survey2.Answer group by survey.Answer, State; quit;