BookmarkSubscribeRSS Feed
Mathis1
Quartz | Level 8

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 ? 

 

2 REPLIES 2
Tom
Super User Tom
Super User

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).

smantha
Lapis Lazuli | Level 10
proc sort data=inputdata nodupkey;
by _all_;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 750 views
  • 0 likes
  • 3 in conversation