BookmarkSubscribeRSS Feed
DeepSiv
Fluorite | Level 6

Hi all

I need to do a sum of across field in a PROC REPORT. My proc report looks like this:

PROC REPORT DATA = TEST;

COLUMN A B C,D;

DEFINE A/GROUP;

DEFINE B/GROUP;

DEFINE C/ACROSS;

DEFINE D/ANALYSIS SUM;

RUN;

This creates a report grouping column A, B and across column C. So if C has two possible values - VAL1, VAL2, then it appears like this:

A     B      VAL1 VAL2

On   Two   80      30

I need a column total of VAL1 and VAL2 in a new field. Something like this

A      B      VAL1    VAL2  TOTAL

On    Two    80         30     110

Thanks in advance.

1 REPLY 1
pfep
Calcite | Level 5

Hi Deep Siv,

You can try something like this :

data tab1;

input c $ year sales;

cards;

a 2009 10

a 2010 10

a 2011 10

a 2012 10

b 2009 10

b 2010 10

b 2011 10

b 2012 10

;run;

proc report data=tab1 ;

columns c   year, sales  sales=salessum;

define c  /group ;

define year/across order=data;

define sales/analysis sum ;

define salessum/sum 'Total Sales';

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 2062 views
  • 0 likes
  • 2 in conversation