Solved
Contributor
Posts: 39

# Summary line in proc print or proc report?

Hi,

I have following data

 obs A B C D 1 Type 1 B1 C1 1 2 Type 1 B1 C2 3 3 Type 2 B2 C3 2 4 Type 3 B3 C4 5

I need a list (proc print or proc repot) like below. The “summary” line should show number of unique observations for variable A, B and C as well as SUM value for variable D.

 A B C D Type 1 B1 C1 1 Type 1 B1 C2 3 Type 2 B2 C3 2 Type 3 B3 C4 5 3 3 4 11

Below simple code get me a little bit forward:

proc print data=test noobs;
var A B C D;
sum D;
run;

But what do I do for A, B and C? I need the number of unique observations for variable A, B and C.

Is this possible with proc print or proc report?

Thanks

Accepted Solutions
Solution
‎09-17-2014 08:44 AM
Super User
Posts: 10,761

## Re: Summary line in proc print or proc report?

Sure .

```data have;
input A & \$ B \$ C \$ D ;
cards;
Type 1  B1  C1 1
Type 1  B1 C2 3
Type 2  B2 C3 2
Type 3  B3 C4 5
;
run;
ods listing close;
ods pdf file='x.pdf' style=sasweb;
proc report data=have nowd;
column a b c d;
define a /display;
define d /display;
compute d;
length x y z \$ 400;
if not find(x,a) then do; x=catx(' ',x,a); xx+1;end;
if not find(y,b) then do; y=catx(' ',y,b);     yy+1;end;
if not find(z,c) then do; z=catx(' ',z,c); zz+1;end;
sum+d;
endcomp;
compute after;
line @1 xx  yy  zz sum;
endcomp;
run;
ods pdf close;
ods listing;

```

Xia Keshan

All Replies
Super User
Posts: 13,498

## Re: Summary line in proc print or proc report?

To get count of unique values you'll need at least one other step. Proc freq or proc means with levels or Proc SQL and select distinct can get the counts of unique values. Proc freq may be the best bet:

SAS Super FREQ
Posts: 9,365

## Re: Summary line in proc print or proc report?

I see how you get all the numbers in your chart except for the count of 5 in the column for C...it looks like the number at the bottom of the report should be 4 for C??

cynthia

Contributor
Posts: 39

## Re: Summary line in proc print or proc report?

Hi Cynthia,

Yes, the number count for C should be 4.

Is it possible to use compute in proc report to get the count?

Solution
‎09-17-2014 08:44 AM
Super User
Posts: 10,761

## Re: Summary line in proc print or proc report?

Sure .

```data have;
input A & \$ B \$ C \$ D ;
cards;
Type 1  B1  C1 1
Type 1  B1 C2 3
Type 2  B2 C3 2
Type 3  B3 C4 5
;
run;
ods listing close;
ods pdf file='x.pdf' style=sasweb;
proc report data=have nowd;
column a b c d;
define a /display;
define d /display;
compute d;
length x y z \$ 400;
if not find(x,a) then do; x=catx(' ',x,a); xx+1;end;
if not find(y,b) then do; y=catx(' ',y,b);     yy+1;end;
if not find(z,c) then do; z=catx(' ',z,c); zz+1;end;
sum+d;
endcomp;
compute after;
line @1 xx  yy  zz sum;
endcomp;
run;
ods pdf close;
ods listing;

```

Xia Keshan

🔒 This topic is solved and locked.