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!
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.