Hi everyone,
I have a dataset with 90 variables, when I want to create a sum-function with the Query Builder I have to dubble-click on each variable.
Is there a way to select all the variables faster? Ideal would be something like: sum(var2 [until] var90).
Thanks,
David
I would use the sum function in a datastep for that. e.g.,
data have;
input var1 $ var2-var6;
group1=sum(var2,var3);
group2=sum(of var4-var6);
cards;
A 4 8 6 9 1
B 9 5 3 0 2
C 2 3 2 3 5
D 1 2 5 9 1
E 9 7 3 4 3
;
Do you need do to it with the Query Builder? It would be a trivial request using proc summary.
Well for this step the proc summary is perfect.
But in a later step I need the group them in 4 big groups... (and I don't know if that's possible with the proc summary)
You would have to explain what you mean by 4 big groups. If it is groups of records, you can use a by variable. If it is groups of variables, you can first use proc transpose (to make the table wide) and then simply use proc summary on the wide tables.
Yes, 4 groups of variables.
Maybe it's more clear with a little example:
var1 var2 var3 var4 var5 var6
A 4 8 6 9 1
B 9 5 3 0 2
C 2 3 2 3 5
D 1 2 5 9 1
E 9 7 3 4 3
And the result should be a new dataset:
var1 group1 group2
A 12 16
B 14 5
C 5 10
...
group1: sum(var1, var2)
group2: sum(var3, var4, var5)
I would use the sum function in a datastep for that. e.g.,
data have;
input var1 $ var2-var6;
group1=sum(var2,var3);
group2=sum(of var4-var6);
cards;
A 4 8 6 9 1
B 9 5 3 0 2
C 2 3 2 3 5
D 1 2 5 9 1
E 9 7 3 4 3
;
This was exactly what I was looking for! Thank you!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.