Hi,
I have this tiny table attached (3 observations) with a lot of variables. I'd like to keep only the variables for which there exists different values between at least 2 observations (or supress variables that have the same values for all the observations). Do you know a simple way to do this ?
The NLEVELS output of PROC FREQ will show you how many distinct values each variable has.
You can use ODS OUTPUT to get the result into a dataset.
ods output nlevels=nlevels;
proc freq data=carross1 nlevel;
tables _all_ / noprint;
run;
You can now pull the list of names that mean you criteria into a macro variable using PROC SQL. Either make a list of the ones to keep or the ones to delete and use the list in a KEEP or DROP statement (or dataset option).
proc sort data=inputdata nodupkey;
by _all_;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.