BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1239
Calcite | Level 5

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

                                         =========

1 ACCEPTED SOLUTION

Accepted Solutions
kuridisanjeev
Quartz | Level 8

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

View solution in original post

7 REPLIES 7
allurai0412
Fluorite | Level 6

hi ,

use compute block.and check

COMPUTE AFTER COUNTRY;

COUNTRY=TRIM(COUNTRY)||'TOTAL"

ENDCOMP;

Regards,

ALLU

1239
Calcite | Level 5

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;

Cynthia_sas
SAS Super FREQ

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

1239
Calcite | Level 5

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.

kuridisanjeev
Quartz | Level 8

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

kuridisanjeev
Quartz | Level 8

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

1239
Calcite | Level 5

Hi Sanjeev,

ThanksSmiley Happy a lot for code. It's working as per the requirement.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1196 views
  • 1 like
  • 4 in conversation