BookmarkSubscribeRSS Feed
SM8
Obsidian | Level 7 SM8
Obsidian | Level 7

So, 

I have two tables that I created using proc sql and then transposed.

 

Here is the code:

 

proc sql;
create table summary as
select count(distinct key) as vistcnt, state,
date, codes, sum(disbursmnt) as paymnt
from meds
where state in ('NY','PA','NJ')
group by state, date, codes;
quit;

proc sort data = summary;
by state codes;
run;

proc transpose data = summary out=visits prefix=visitcount;
var vistcnt; id date; by state codes;
run;

proc transpose data = summary out=payments prefix=dollars;
var paymnt; id date; by state codes;
run;

 

How can I put these two together and do a summary for the total of vistcnt and paymnt?

2 REPLIES 2
Kurt_Bremser
Super User

Summarize before you transpose. Long datasets are always easier for processing than wide ones.

For detailed help, provide the untransposed dataset in a data step with datalines.

SM8
Obsidian | Level 7 SM8
Obsidian | Level 7

Here is the code before the transpose:

proc sql;
create table summary as
select count(distinct key) as vistcnt, state,
date, codes, sum(disbursmnt) as paymnt
from meds
where state in ('NY','PA','NJ')
group by state, date, codes;
quit;

proc sort data = summary;
by state codes;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 475 views
  • 0 likes
  • 2 in conversation