turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- BI
- /
- Enterprise Guide
- /
- Program to find a variable

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2016 07:24 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sean_OConnor

12-19-2016 07:38 AM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sean_OConnor

12-19-2016 07:40 AM

You can define an array over those variables:

`array all_my_xs {*} x1=x400;`

Then you can loop through the array.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sean_OConnor

12-19-2016 09:32 AM

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.