BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I have  simple proc report example.

I have 4 numeric fields and I want to create one more column with sum of x1,x2,x3,x4.

Please pay attention that it might happen that in x1,x2,x3,x4 there is a null value.

 

 

 Data tbl;
 input branch X1  X2  X3  X4;
 cards;
 1  10 20 30 40 
 2  15 20 25 30
 3  35 40 45 50
 4  55 60 65 .
 ;
 run;


proc report data=tbl  headline split='#' spacing=1 nowd
style(report)={cellpadding=1 cellspacing=1}
style(header)={font_size=2  font_weight=MEDIUM  font_face=david  background=cx99ccaa}
style(column)={font_size=1}; 
columns  branch X1  X2  X3  X4 ;
define branch/ display 
	"Branch"  center;
define X1/  Display "X1 amount";
define X2/  Display "X2 amount";
define X3/  Display "X3 amount";
define X4/  Display "X4 amount";
Run;

1 REPLY 1
Ronein
Meteorite | Level 14

I found the answer

 

 


proc report data=tbl headline split='#' spacing=1 nowd
style(report)={cellpadding=1 cellspacing=1}
style(header)={font_size=2 font_weight=MEDIUM font_face=david background=cx99ccaa}
style(column)={font_size=1};
columns branch X1 X2 X3 X4 total;
define branch/ display
"Branch" center;
define X1/ Display "X1 amount";
define X2/ Display "X2 amount";
define X3/ Display "X3 amount";
define X4/ Display "X4 amount";
define total/computed;
compute total;
total=sum(x1,x2,x3,x4);./*Will not get null if there is null value in x1,x2,x3,x4*/
endcomp;
Run;
/*total=x1+x2+x3+x4; */
/*Will get null if there is null value in x1,x2,x3,x4*/

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
  • 560 views
  • 0 likes
  • 1 in conversation