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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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