SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
joachimg
Obsidian | Level 7

Hi all, I don't know if my title makes any sense, but here is the issue. I have a dataset with the variables year, cause of death, race/ethnicity, and ratio. I want to create a table that is sort of like a 2x2 table by cause, except instead of having frequencies in the table, I want the ratio variable to populate the table. Like, if I have five categories for cause of death, four years, and 5 categories of race/ethnicity, I want five tables (or one big table) that look like what would be generated from this code:

proc sort data=dataset; by cause; run;
proc freq data=dataset;
tables year*race;
by cause;
run;

Except I would see the ratios in the table, and be able to say (for example) that the mortality ratio for NH white participants in 2012 whose cause of death was suicide is 3.5 per 100,000 (totally made up number). Is this possible, either in SAS or through exporting into Excel? I'm not sure how clear this is so please let me know if I can clarify anything. Thank you. 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

If your final desired output is a Excel file, you could try to use PROC REPORT.

If you want sas dataset,that is another story.

 

data have;
call streaminit(123);
do cause='a','b','c';
 do year=2020 to 2025;
  do race='x','y','z';
    ratio=rand('uniform');
	output;
  end;
 end;
end;
run;

options nobyline;
ods _all_ close;
ods excel file='c:\temp\want.xlsx' options(embedded_titles='yes' sheet_name='RxC ratio table' sheet_interval='none');
title "Cause: #byval1";
proc report data=have nowd;
by cause;
columns year ratio,race;
define year/group;
define race/across;
define ratio/analysis '';
run;
ods excel close;

Ksharp_0-1742951234434.png

 

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

You need a cross tabulation table (or crosstab) and you can easily make that with PROC REPORT.

 

See :

Paper 388-2014

Sailing Over the ACROSS Hurdle in PROC REPORT

Cynthia L. Zender, SAS Institute Inc., Cary, NC

https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf

 

BR, Koen

Ksharp
Super User

If your final desired output is a Excel file, you could try to use PROC REPORT.

If you want sas dataset,that is another story.

 

data have;
call streaminit(123);
do cause='a','b','c';
 do year=2020 to 2025;
  do race='x','y','z';
    ratio=rand('uniform');
	output;
  end;
 end;
end;
run;

options nobyline;
ods _all_ close;
ods excel file='c:\temp\want.xlsx' options(embedded_titles='yes' sheet_name='RxC ratio table' sheet_interval='none');
title "Cause: #byval1";
proc report data=have nowd;
by cause;
columns year ratio,race;
define year/group;
define race/across;
define ratio/analysis '';
run;
ods excel close;

Ksharp_0-1742951234434.png

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3 replies
  • 500 views
  • 3 likes
  • 3 in conversation