BookmarkSubscribeRSS Feed
KimW
Calcite | Level 5

I have a dataset where I need to calculate the rate of opioid episodes (OpioidEpisodes/TotalEpisodes) by county. I have spent many hours trying to come up with the right code. Can someone please tell me if I'm on the right track?20241207_164549[1].jpg20241207_162841[1].jpg

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This looks very close to me, small changes needed to PROC SUMMARY. You need a data step after PROC SUMMARY to do the actual division from the results in data set TOTALS.

 

proc summary data=____________ nway;
    class county;
    var opioidepisodes totalepisodes;
    output out=totals sum=;
run;

data totals1;
    set totals;
    rate=opioidepisodes/totalepisodes;
run;
    

 

 

PS: When you want to show us your code, copy it as text and paste it into the window that appears when you click on the "little running man" icon. Making screen captures of text is not a good thing to do.

--
Paige Miller
ballardw
Super User

IF, and I know this is a big if, your variables are numeric coded as 0 and 1 then the MEAN of the variable is the percent of 1 values for the non-missings.

Example if your OpiodEpisodes have 30 1 values and 20 0 values then the mean would be 30/50 or 0.60 meaning 60 percent.

If that seems likely to be valid for your data I would expect something like this might work.

Proc summary data=mydata.opioidcounty;
  by county payer; /*Or use class county payer; */
  var opioidEpisodes TotalEpisodes;
  output out=totals Sum= OpioidEpisodes TotalEpisodes mean=opioidpercentage    totalpercentage;
run;

I say "something like" as I very strongly suspect the output you show does not come from the code shown. The Var variables shown would have a hard time generating an output variable named TotalEpisodes because your code includes a space in the name. Also since the var Payer was not one the output statement by name it would not be included in the output.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 537 views
  • 0 likes
  • 3 in conversation