BookmarkSubscribeRSS Feed
dali74
Fluorite | Level 6

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

 

4 REPLIES 4
Reeza
Super User

@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

dali74
Fluorite | Level 6
Sorry! but i put with data statement. I know i can do it with proc means.
ballardw
Super User

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.

novinosrin
Tourmaline | Level 20

 

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.

 

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
  • 4 replies
  • 855 views
  • 0 likes
  • 4 in conversation