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?
@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 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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.