Hi Kurl, thanks for answering my post and reply so quick. Your solution are exactly what was after and your explanation also helped. Kind Regards
This is where the "automatic remerge" of SAS SQL comes in handy:
data have;
input serviceitemcd $ Count;
datalines;
AB 10
AC 20
AD 30
;
proc sql;
create table want as
select
serviceitemcd,
count,
sum(count) as grandtotal
from have
union all
select
"Total" as serviceitemcd,
sum(count) as count,
sum(count) as grandtotal
from have
;
quit;
Hi Kurl, thanks for answering my post and reply so quick. Your solution are exactly what was after and your explanation also helped. Kind Regards
Hello @Collingwoodeyed,
Glad to see that KurtBremser's solution worked for you. Then it would be fair and help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select his post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
Sorry if I did something wrong. I just wanted to personally acknowledge Kurl for answering my question. I did mark this as solved, so unsure why you are querying this (I didn't do it straight away, as didn't realise that this needed to be done. If I have missed something, then I am sorry
You're welcome. It's great to write a "thank you" post, but the post marked as the solution (with the green background color) should ideally be the one which contains the actual solution (KurtBremser's post in this case), so that later readers with a similar problem can quickly find the helpful SAS code (rather than a post only referring to it). Moreover, there are rankings based on the number of provided solutions (Top Solution Authors Leaderboard) and obviously it's KurtBremser who deserves the point here, but he won't get it until his post is marked as the solution.
Hi @Collingwoodeyed and welcome to the SAS Support Communities!
As @Kurt_Bremser has demonstrated, a single PROC SQL step can streamline the process and replace several PROC SUMMARY and DATA steps.
Just to provide a fix to your last DATA step:
data want;
if _n_=1 then set physio_tot;
set dat.physio_item physio_tot(drop=GrandTotal);
run;
The purpose of the first SET statement is basically to read the single value of GrandTotal, which is then automatically retained through all iterations of the DATA step. It also reads serviceitemcd and Count (which is not bad because it helps to produce the desired variable order) from physio_tot, but their values are overwritten by the second SET statement. Without the DROP= dataset option also the GrandTotal would be overwritten with missing values for the observations from dat.physio_item.
Thank-you also for your answer and going to trouble to explain an alternative solution.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.