BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AbuYusuf
Calcite | Level 5

Hi,

 

I am trying to do a simple thing: calculate discharge rate by disease category and year. I am trying to  figure out how to use proc report to do that, and I can't get it to work. My data has these  4 variables: disease, year, number of discharges, and count (population by age and sex). Here is the code I am using:

 

proc report data=rmtwork.table1;
title "Mental health discharge rate per 100,000 by diagnostic category.";
column disease discharges count year, poprate;
define disease / group;
define year / across order=freq width=4 'Year';
define discharge / 'Number of  discharges';

define poprate / computed format=6.5 'Rate per 100,000';

compute poprate;
poprate = discharges.sum/count.sum*100000;
endcomp;
run;

 

The code generates missing values. It works without the across statement, but not when I try to generate these rates by year.

 

I'd be grateful if you could help me sort this out!

Thank you,

i.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26

Hi:

  I'm confused. It looks like you want to calculate POPRATE for each value of YEAR. So I would normally assume that you want the calculation to be based on the discharge and count for EACH separate YEAR. However, you only have POPRATE under YEAR. You don't have DISCHARGE and COUNT under YEAR.

 

  Having data would help. I also think you will need absolute column numbers used for your COMPUTE block. Any variables under an ACROSS item that you are calculating must be referenced by absolute column number. I know there are previous postings about absolute column numbers.

 

  Using some fake data starting from SASHELP.PRDSALE below shows what your original code would result in versus using absolute column numbers and putting discharges and count under each year.

poprate_across.png

 

 After you are sure the calculations are correct (for report 2), then you could use NOPRINT on DISCHARGES and COUNT to hide them on the report. Note that I did not multiply by 100000 because I was really just trying to show the use of absolute column numbers and a simple division worked for that.

 

Cynthia

View solution in original post

10 REPLIES 10
Reeza
Super User
Can you provide sample data and show what you want as output? Fake data is totally fine.
AbuYusuf
Calcite | Level 5

Thank you for your response!

 

I use proc tabulate to create this table:

 20102011201220132014201520162017
 dischargescountdischargescountdischargescountdischargescountdischargescountdischargescountdischargescountdischargescount
Excluded5625964434318259644344122596443440825964434172259644349025964434129259644342725964434
Organic disorders12752604231518542604231519282604231520622604231521662604231523812604231524502604231568126042315
Substance-related disorders19302607566726562607566728052607566729572607566732542607566735832607566739612607566797926075667
Schizophrenic and psychotic disorders22942607566730992607566731572607566732122607566731932607566731772607566734722607566790126075667
Mood disorders325226075667442726075667457226075667458326075667457426075667451326075667473026075667121226075667
Anxiety disorders4322604231563926042315725260423157712604231579726042315849260423157212604231515626042315
Personality disorders2462607566732326075667317260756673452607566739426075667455260756676292607566718826075667
Other disorders171426075667244826075667274526075667276226075667290326075667302526075667276626075667650

26075667

 

 

Now I am trying to use proc report to create this:

 20102011201220132014201520162017
 raterateraterateraterateraterate
Excluded        
Organic disorders        
Substance-related disorders        
Schizophrenic and psychotic disorders        
Mood disorders        
Anxiety disorders        
Personality disorders        
Other disorders        
Reeza
Super User
I can almost guarantee that PROC TABULATE did not generate a table like that into a data set. What does the data set look like?
AbuYusuf
Calcite | Level 5

Why not?

 

proc tabulate data=rmtwork.table1;
format province province.;
format discatv2 disease.;


class discyear / order=unformatted missing;
class discatv2 / order=unformatted missing;

 

var LOS_N;
var population;

 

table discatv2, discyear*(LOS_N population);

run;

 

where discatv2 = disease, discyear = year, los_n = discharge, and population = count as I called them in the previous post.

 

It's a large administrative data set

Reeza
Super User

PROC TABULATE gives you output in a displayed format, not in a table that you can use to feed into PROC REPORT. You can capture the data from PROC TABULATE using an OUT= or ODS OUTPUT statement but I don't see any indication of that. And the format doesn't match the displayed output.

 

EDIT: I would suggest providing a sample of the original data and showing what you expect as output. 

Multiple edits.


@AbuYusuf wrote:

Why not?

 

proc tabulate data=rmtwork.table1;
format province province.;
format discatv2 disease.;


class discyear / order=unformatted missing;
class discatv2 / order=unformatted missing;

 

var LOS_N;
var population;

 

table discatv2, discyear*(LOS_N population);

run;

 

where discatv2 = disease, discyear = year, los_n = discharge, and population = count as I called them in the previous post.

 

It's a large administrative data set


 

ballardw
Super User

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

AbuYusuf
Calcite | Level 5

thank you!

Cynthia_sas
Diamond | Level 26

Hi:

  I'm confused. It looks like you want to calculate POPRATE for each value of YEAR. So I would normally assume that you want the calculation to be based on the discharge and count for EACH separate YEAR. However, you only have POPRATE under YEAR. You don't have DISCHARGE and COUNT under YEAR.

 

  Having data would help. I also think you will need absolute column numbers used for your COMPUTE block. Any variables under an ACROSS item that you are calculating must be referenced by absolute column number. I know there are previous postings about absolute column numbers.

 

  Using some fake data starting from SASHELP.PRDSALE below shows what your original code would result in versus using absolute column numbers and putting discharges and count under each year.

poprate_across.png

 

 After you are sure the calculations are correct (for report 2), then you could use NOPRINT on DISCHARGES and COUNT to hide them on the report. Note that I did not multiply by 100000 because I was really just trying to show the use of absolute column numbers and a simple division worked for that.

 

Cynthia

AbuYusuf
Calcite | Level 5

Hello Cynthia,

 

Thank you very much! That was exactly what I wanted to do. I tried putting discharges and count under year, but the code didn't work out (for another reason as I now understand), so I gave up on that approach.

 

Thank you very much!

Cynthia_sas
Diamond | Level 26
Hi: Glad it worked for you! Here's a paper about using ACROSS that may help you understand how it works: http://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf

Cynthia

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 5728 views
  • 0 likes
  • 4 in conversation