BookmarkSubscribeRSS Feed
Sean_OConnor
Fluorite | Level 6

Dear Users,

 

I'm new to SAS so I'm not entirely sure if something like this is even possible so would apologies if it's not. 

 

At present I have a dataset which has information on over 1,000,000 individuals. Moreover, the dataset also consists of over 400 variables. 

 

What I would like to do is aggregate each variable to get a total and then compare each total to a particular number to understand if there's a match.

 

So I'd like to tell SAS to sum variable x1 then x2, x3, all the way to x400. 

 

From there I'd like to be able to see does the aggregate of x1 = 500, or does x2, x3 etc. Simply put does any of these 400 variables match 500 and if so which one.

Hopefully, I've been clear on what I'd like to do and any comments would be great.

 

Kind regards,

Sean 

3 REPLIES 3
Reeza
Super User

Your best bet for more help is to post sample data and expected output.
Because you have 400 variables you may also want to thoroughly familiarize yourself with variables lists, ways to reference variables withou explcilty typing each name.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

 

Are you coding or using GUI (tasks)  in EG? 

 

For summarizing data use PROC MEANS/SUMMARY

 

 

For filtering ata across a wide range of variables look at WHICHN function with a data step and/or an Array. 

 

Your best bet for more help is to post sample data and expected output. 

Because you have 400 variables you may also want to thoroughly familiarize yourself with variables lists, ways to reference variables withou explcilty typing each name. 

 

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Astounding
PROC Star

If you're new to SAS, I suspect you need a little more guidance on this.  This would be a good starting point:

 

proc summary data=have;

var _numeric_;

output out=stats (drop=_type_ _freq_) sum=;

run;

 

This gives you a data set named STATS with a single observation.  All the original variable names are there, but they now hold the sum across all the original observations.

 

To search for all variables with a sum of 500, you could proceed:

 

data vars_500;

set stats;

length varname $ 32;

array nums {*} _numeric_;

do _n_=1 to dim(nums);

   if nums{_n_}=500 then do;

      varname = vname(nums{_n_});

      output;

   end;

end;

run;

 

In VARS_500, you will have a list of all variable names that summed to 500.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1042 views
  • 0 likes
  • 4 in conversation