BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
karan96
Fluorite | Level 6


data test ;
input x;
datalines;
1
2
3
4
5
6
7
;
run;
Q) how can I get total of x in single observation ?

1 ACCEPTED SOLUTION

Accepted Solutions
hashman
Ammonite | Level 13

@karan96:

Any of the steps 2 through 4 below will work:

data test ;                                               
  input x ;                                               
  cards ;                                                 
1                                                         
2                                                         
3                                                         
4                                                         
5                                                         
6                                                         
7                                                         
;                                                         
run ;                                                     
                                                         
data need (drop = x) ;                                    
  set test end = z ;                                      
  sum_x + x ;                                             
  if z ;                                                  
run ;                                                     
                                                          
proc sql ;                                                
  create table need as select sum (x) as sum_x from test ;
quit ;                                                    
                                                         
proc means data = test noprint ;                          
  var x ;                                                 
  output out = need (drop = _:) sum = sum_x ;             
run ;                                                     

Kind regards

Paul D. 

View solution in original post

2 REPLIES 2
karan96
Fluorite | Level 6

data test ;

input x;

datalines;

1

2

3

4

5

6

7

;

run;

Q) how can I get total of x  in single observation ?

hashman
Ammonite | Level 13

@karan96:

Any of the steps 2 through 4 below will work:

data test ;                                               
  input x ;                                               
  cards ;                                                 
1                                                         
2                                                         
3                                                         
4                                                         
5                                                         
6                                                         
7                                                         
;                                                         
run ;                                                     
                                                         
data need (drop = x) ;                                    
  set test end = z ;                                      
  sum_x + x ;                                             
  if z ;                                                  
run ;                                                     
                                                          
proc sql ;                                                
  create table need as select sum (x) as sum_x from test ;
quit ;                                                    
                                                         
proc means data = test noprint ;                          
  var x ;                                                 
  output out = need (drop = _:) sum = sum_x ;             
run ;                                                     

Kind regards

Paul D. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1032 views
  • 0 likes
  • 2 in conversation