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
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.
You can define an array over those variables:
array all_my_xs {*} x1=x400;
Then you can loop through the array.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: