Hi,
I need "Total" text to be displayed in the last row along with the total number. I have tried with proc report and couldn't achieve. Please find the country.sas program and help me in achieving the same.
Thanks in Advance.
Current Output:
ID COUNTRY COUNT
A01 FINLAND 0
A02 FRANCE 0
A03 GERMANY 11
A04 ITALY 0
A05 UNITED KINGDOM 34
A06 UNITED STATES 23
=========
68
=========
Desired Output:
ID COUNTRY COUNT
A01 FINLAND 0
A02 FRANCE 0
A03 GERMANY 11
A04 ITALY 0
A05 UNITED KINGDOM 34
A06 UNITED STATES 23
=========
Total 68
=========
Hi..
Try this Proc Report Code.
Tested and working perfectly..
Data Test;
input ID $5. COUNTRY $20. COUNT ;
cards;
A01 FINLAND 0
A02 FRANCE 0
A03 GERMANY 11
A04 ITALY 0
A05 UNITED KINGDOM .
A06 UNITED STATES 23
;
run;
Proc Report data=test out=t;
columns ID Country Count;
define ID/Display ;
Define Country/Display;
Rbreak after/summarize Dul Dol;
Compute ID;
If _BREAK_="_RBREAK_" then
ID="Total";
endcomp;
run;
Thanks &Regards.
Sanjeev.K
hi ,
use compute block.and check
COMPUTE AFTER COUNTRY;
COUNTRY=TRIM(COUNTRY)||'TOTAL"
ENDCOMP;
Regards,
ALLU
Hi,
I tried using compute block but its not working.
proc report data = country nowd;
columns id country count;
define id / display;
define country / order;
rbreak after / summarize style=[fontweight=bold color=black] dol dul ;
COMPUTE AFTER country;
country=TRIM(country)||'TOTAL';
ENDCOMP;
run;
Hi:
It looks like ID is character with a length of 3??? The problem is that when you use your compute block technique, you are limited to the length of the variable in the column that you want to assign the Total string to. For example, the SEX variable in SASHELP.CLASS is a character variable with a length of 1. See the problem with your code approach shown in the screenshot. And one possible solution, shown in the other screenshot.
cynthia
Hi, Is there any other approach other than proc report? I want only Total and text as "Total" at the last row. Please help me.
Hi..
Your requirement can be easily achievable with Proc report as suggested.
As you mentioned in above post ,i can provide the solution "Other then Proc Report".but i am not sure this is the right way to achieve your requirement.
Here is the Solution for your requirement..
Data Test;
input ID $4. COUNTRY $20. COUNT ;
cards;
A01 FINLAND 0
A02 FRANCE 0
A03 GERMANY 11
A04 ITALY 0
A05 UNITED KINGDOM 34
A06 UNITED STATES 23
;
run;
Data t(Drop=Count1);
Format ID $6.;
set test end=last ;output;
retain Count1 0;
Count1=sum(Count1,Count);
if last then do;
ID="Total";
Count=Count1;
COUNTRY=' ';output;
end;
run;
Proc print;
run;
Thanks & Regards.
Sanjeev.K
Hi..
Try this Proc Report Code.
Tested and working perfectly..
Data Test;
input ID $5. COUNTRY $20. COUNT ;
cards;
A01 FINLAND 0
A02 FRANCE 0
A03 GERMANY 11
A04 ITALY 0
A05 UNITED KINGDOM .
A06 UNITED STATES 23
;
run;
Proc Report data=test out=t;
columns ID Country Count;
define ID/Display ;
Define Country/Display;
Rbreak after/summarize Dul Dol;
Compute ID;
If _BREAK_="_RBREAK_" then
ID="Total";
endcomp;
run;
Thanks &Regards.
Sanjeev.K
Hi Sanjeev,
Thanks a lot for code. It's working as per the requirement.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.