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

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

;

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

Do you need do to it with the Query Builder?  It would be a trivial request using proc summary.

DavidDemeyer
Calcite | Level 5

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)

art297
Opal | Level 21

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.

DavidDemeyer
Calcite | Level 5

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)

art297
Opal | Level 21

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

;

DavidDemeyer
Calcite | Level 5

This was exactly what I was looking for! Thank you!

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

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 30280 views
  • 1 like
  • 2 in conversation