BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10

I initially ran a data set which looks like this which had 34 columns and each column had 18 obs.:

OBS      KL1  KL2..KL3 KL4....KL34

1

..

 18

This data set ran okay with proc means giving me the sum of KL1  KL2 etc. each in a row resulting in the data set all below.

I would like to obtain the sum of KL1-KL3 for the data set all.

 

Variable    Sum

KL1            0.014

KL2             0.009

KL3             0.034

proc means data =all sum;
var KL1-Kl3;
output out=klall  sum=/autoname;
run;

When I run the above code I get an error that KL1 not found.  Can some on tell me why it is not reading the variables? 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@jacksonan123 wrote:

I initially ran a data set which looks like this which had 34 columns and each column had 18 obs.:

OBS      KL1  KL2..KL3 KL4....KL34

1

..

 18

This data set ran okay with proc means giving me the sum of KL1  KL2 etc. each in a row resulting in the data set all below.

I would like to obtain the sum of KL1-KL3 for the data set all.

 

Variable    Sum

KL1            0.014

KL2             0.009

KL3             0.034

proc means data =all sum;
var KL1-Kl3;
output out=klall  sum=/autoname;
run;

When I run the above code I get an error that KL1 not found.  Can some on tell me why it is not reading the variables? 


Use the output data set Klall as input to a data step and do the addition there:

 

data want;

   set klall;

   kl1_kl3_sum = sum(kl1_sum, kl2_sum,kl3_sum);

run;

 

or optionally sum each record prior to proc means add that variable to the VAR statement: sums of sums don't matter on the order.

View solution in original post

2 REPLIES 2
ballardw
Super User

@jacksonan123 wrote:

I initially ran a data set which looks like this which had 34 columns and each column had 18 obs.:

OBS      KL1  KL2..KL3 KL4....KL34

1

..

 18

This data set ran okay with proc means giving me the sum of KL1  KL2 etc. each in a row resulting in the data set all below.

I would like to obtain the sum of KL1-KL3 for the data set all.

 

Variable    Sum

KL1            0.014

KL2             0.009

KL3             0.034

proc means data =all sum;
var KL1-Kl3;
output out=klall  sum=/autoname;
run;

When I run the above code I get an error that KL1 not found.  Can some on tell me why it is not reading the variables? 


Use the output data set Klall as input to a data step and do the addition there:

 

data want;

   set klall;

   kl1_kl3_sum = sum(kl1_sum, kl2_sum,kl3_sum);

run;

 

or optionally sum each record prior to proc means add that variable to the VAR statement: sums of sums don't matter on the order.

jacksonan123
Lapis Lazuli | Level 10
The final code based upon your suggestion that worked was:

Proc means data =kl sum;

Var skl1-skl3;

Output out =klall sum=autolabel; run;

Data want;

Set klall;

asum=sum(skl1,skl2,skl3);

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 858 views
  • 0 likes
  • 2 in conversation