DATA Step, Macro, Functions and more

Summarizing Data in Multiple Columns

Reply
Contributor
Posts: 28

Summarizing Data in Multiple Columns

[ Edited ]

is it possible to create a dataset with sum in multiple columns?

 

With datat  statement

 

 

Var1   var2 ..................... varn

 1          10                        20

 4          10                        20

6          10                        20

 10          10                        20

 

totalvar1=21

totalvar2=40

totalvar2=80

 

Super User
Posts: 19,878

Re: Summarizing Data in Multiple Columns


dali74 wrote:

is it possible to create a dataset with sum in multiple columns?

 

 

 


Yes. Your math appears incorrect or is it bad sample data?

 

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic

Contributor
Posts: 28

Re: Summarizing Data in Multiple Columns

Sorry! but i put with data statement. I know i can do it with proc means.
Super User
Posts: 11,343

Re: Summarizing Data in Multiple Columns

Do you want the total to manipulate in another procedure for some reason? Or do you want to create a report with a sum total row?

 

Generally putting a total in the data leads to a number of potential problems if the data is used for input into other procedures.

PROC Star
Posts: 283

Re: Summarizing Data in Multiple Columns

[ Edited ]

 

data have;
input v1-v3;
datalines;
1          10                        20
 4          10                        20
6          10                        20
 10          10                        20
 ;
 
 
proc means data= have;
var v1-v3 ;
output out=want(drop=_: ) sum=;
run;
 

Note: Edited by @Reeza to remove emojis from code.

 

Ask a Question
Discussion stats
  • 4 replies
  • 111 views
  • 0 likes
  • 4 in conversation