So, I'm looking to do a summary of a dataset using proc tabulate to get totals for the visitcount and payment variables for each quarter. I also want it so that my output is sent directly to excel. How can I do this?
proc sql;
create table statesums as
select count(pkey) as visitcount, state,
date, code, sum(dis) as payment
from medcla
where state in ('NY','PA','NJ')
group by state, date, code;
quit;
proc sort data = statesums;
by state code; run;
proc transpose data = statesums out=visits prefix=visitcount;
var visitcount; id date; by =state hcpcs;
run;
proc transpose data = statesums out=payments prefix=dollars;
var payment; id date; by state code;
run;
proc sql;
create table totals as
select * from vists as x left join payments as y
on x.state = y.state
and x.code = y.code;
quit;
Can you show us what the output ought to look like?
Honestly, I don't think any of your code is needed, PROC REPORT ought to produce the table directly from the original data.
If you are going to ask a bunch of related questions you really should provide an example data set we can work with.
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 </> icon or attached as text to show exactly what you have and that we can test code against.
No idea how your code relates to your question, here's how I'd do it.
ods excel file="/folders/myfolders/demo.xlsx" style=meadow;
proc tabulate data=sashelp.stocks;
class stock date;
format date yyq6.;
var open;
table date*stock, open*MIN open*MAX;
run;
ods excel close;
@SM8 wrote:
So, I'm looking to do a summary of a dataset using proc tabulate to get totals for the visitcount and payment variables for each quarter. I also want it so that my output is sent directly to excel. How can I do this?
proc sql; create table statesums as select count(pkey) as visitcount, state, date, code, sum(dis) as payment from medcla where state in ('NY','PA','NJ') group by state, date, code; quit; proc sort data = statesums; by state code; run; proc transpose data = statesums out=visits prefix=visitcount; var visitcount; id date; by =state hcpcs; run; proc transpose data = statesums out=payments prefix=dollars; var payment; id date; by state code; run; proc sql; create table totals as select * from vists as x left join payments as y on x.state = y.state and x.code = y.code; quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.