Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- PROC PRINT sum A by B

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 01:23 PM

I am trying to use PROC PRINT to output sum variable A by variable B with an external printto reference. There are many distinct values of A for each B.

I have attempted to use:

proc print data=x;

sum A;

by B;

run;

Does anyone have insight of a better way to achieve the goal of outputting sum A by B?

I have attempted to use:

proc print data=x;

sum A;

by B;

run;

Does anyone have insight of a better way to achieve the goal of outputting sum A by B?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 02:11 PM

Can you provide sample inbound and outbound data sets so that we can better determine your question.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 02:18 PM

A mockup of data x is below. I am trying to suppress the observations in the output so sum values print for A, B and C. If I use noobs after proc print the obs. record number is suppressed but the list of obs. still posts.

I am just looking for sums.

I would like to generate

sum A = 41

sum B = 45

sum C = ..

data x:

A B

1 12

1 14

1 15

2 3

2 9

2 10

2 12

2 11

3 66

3 71

3 23

3 8

3 9

What I get is:

12

14

15

__A SUM__

41

I am just looking for sums.

I would like to generate

sum A = 41

sum B = 45

sum C = ..

data x:

A B

1 12

1 14

1 15

2 3

2 9

2 10

2 12

2 11

3 66

3 71

3 23

3 8

3 9

What I get is:

12

14

15

__A SUM__

41

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 02:42 PM

> data x:

> A B

> 1 12

> 1 14

> 1 15

> 2 3

> 2 9

> 2 10

> 2 12

> 2 11

> 3 66

> 3 71

> 3 23

> 3 8

> 3 9

proc means data= x ;

class a ;

var b ;

output sum= out= x_summary ;

run;

then choose what to do with the summary totals in data set x_summary.

Output data set x_summary will hold the total value of B for each value of A.

The variables will be:

A

B (being the sum of B within A )

_freq_ (the number of rows in X for the current value of A)

_type_ (=0 for overall total and 1 for the total lines of each A)

better documentation can be found at

http://support.sas.com/documentation/cdl/en/allprodsproc/63875/HTML/default/a003135046.htm#a00314568...

good luck

peterC

> A B

> 1 12

> 1 14

> 1 15

> 2 3

> 2 9

> 2 10

> 2 12

> 2 11

> 3 66

> 3 71

> 3 23

> 3 8

> 3 9

proc means data= x ;

class a ;

var b ;

output sum= out= x_summary ;

run;

then choose what to do with the summary totals in data set x_summary.

Output data set x_summary will hold the total value of B for each value of A.

The variables will be:

A

B (being the sum of B within A )

_freq_ (the number of rows in X for the current value of A)

_type_ (=0 for overall total and 1 for the total lines of each A)

better documentation can be found at

http://support.sas.com/documentation/cdl/en/allprodsproc/63875/HTML/default/a003135046.htm#a00314568...

good luck

peterC

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 02:46 PM

Hi:

It seems to me that you do not want a DETAIL report (where you see 1 report row for every observation in the original input data). You describe a SUMMARY report (where every report row represents the information for a group of observations).

SAS has many, many summary-level procedures: PROC SQL, PROC MEANS, PROC TABULATE, PROC REPORT.

Depending on what you want to do (generate output dataset or generate an HTML, RTF or PDF report), you might try starting with PROC MEANS and then graduate to TABULATE or REPORT if MEANS isn't what you want.

cynthia

[pre]

ods html file='c:\temp\examp_means.html' style=sasweb;

proc means data=x sum maxdec=0;

var a b;

run;

ods html close;

[/pre]

It seems to me that you do not want a DETAIL report (where you see 1 report row for every observation in the original input data). You describe a SUMMARY report (where every report row represents the information for a group of observations).

SAS has many, many summary-level procedures: PROC SQL, PROC MEANS, PROC TABULATE, PROC REPORT.

Depending on what you want to do (generate output dataset or generate an HTML, RTF or PDF report), you might try starting with PROC MEANS and then graduate to TABULATE or REPORT if MEANS isn't what you want.

cynthia

[pre]

ods html file='c:\temp\examp_means.html' style=sasweb;

proc means data=x sum maxdec=0;

var a b;

run;

ods html close;

[/pre]

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 04:03 PM

wow

5 minutes and 3 substantial responses

what a channel!

5 minutes and 3 substantial responses

what a channel!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 05:22 PM

data x;

infile datalines dlm='09'x;

input a b :8.;

datalines;

1 12

1 14

1 15

2 3

2 9

2 10

2 12

2 11

3 66

3 71

3 23

3 8

3 9

;

run;

proc tabulate data=x out=y;

var a b;

table a*sum b*sum;

run;

proc transpose data=y(keep=a_sum b_sum) out=z; run;

proc print data=z noobs; run;

Output:

a_Sum 28

b_Sum 263

infile datalines dlm='09'x;

input a b :8.;

datalines;

1 12

1 14

1 15

2 3

2 9

2 10

2 12

2 11

3 66

3 71

3 23

3 8

3 9

;

run;

proc tabulate data=x out=y;

var a b;

table a*sum b*sum;

run;

proc transpose data=y(keep=a_sum b_sum) out=z; run;

proc print data=z noobs; run;

Output:

a_Sum 28

b_Sum 263

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2011 02:43 PM

Hello Jdub,

I guess that you need something like this:

[pre]

proc means data=x nway noprint;

output out=sum(drop=_ sum=;

var b;

class a;

run;

proc print data=sum;

id a;

var b;

run;

[/pre]

Sincerely,

SPR

I guess that you need something like this:

[pre]

proc means data=x nway noprint;

output out=sum(drop=_ sum=;

var b;

class a;

run;

proc print data=sum;

id a;

var b;

run;

[/pre]

Sincerely,

SPR