delete the variable that have the same value

Reply
Occasional Contributor
Posts: 7

delete the variable that have the same value

hallo,

how kann i find or delete if the any Variable in a table have the same value?
for Ex:
if the var1 have only  value "test" then  i dont need that Variable.


I have 1478 Variable. i can not look at every Variable wiht Prog tabulate or freq.

best Regards
Celal

Respected Advisor
Posts: 3,777

Re: delete the variable that have the same value

Consider this proc freq.   Depending on your data this may be "too much".  If you have variables that you know have more than one level you could drop them from consideration.  data=sashelp.heart(drop=.......);

ods select nlevels;
ods output nlevels=nlevels;
proc freq data=sashelp.heart nlevels;
  
run;
ods select all;
Occasional Contributor
Posts: 7

Re: delete the variable that have the same value

Thanks but there is no error message:

ERROR: The SAS System stopped processing this step because of insufficient memory

Do you know another way? or with macro?

Thanks a lot

Respected Advisor
Posts: 3,777

Re: delete the variable that have the same value

I suspected that, don't do so many variables at once and or drop any you know do no need to be tested.

Super User
Posts: 5,085

Re: delete the variable that have the same value

For numeric variables, it would be possible to use PROC MEANS instead of PROC FREQ.  The program could compare the MIN to the MAX for each variable, to see whether they differ.  (That would not identify variables that are always either missing or some other constant value.)  The difficultly with that approach is that it gets a little complex.  A simpler way would be to have PROC MEANS compute the range:

proc means data=have noprint;

  var _numeric_;

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

run;

The values in the output data set should be easy to parse in a DATA step to figure out which values change.  The only complication is that the DATA step would need to use an array with the VNAME function to determine the original variable name.

That approach would let you limit PROC FREQ to handling just the character variables ... possibly with enough memory to do the job.

Good luck.

Respected Advisor
Posts: 3,777

Re: delete the variable that have the same value

I think this SAS-L thread address the subject well.

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0712C&L=sas-l&D=0&P=42815

It includes participation from some real SAS programming "heavy hitters" and one not so much (me).

Respected Advisor
Posts: 3,124

Re: delete the variable that have the same value

Thanks, DN. That was a heck of thread. Many famous names. Are they all retired or some? Don't see them often on SAS-L anymore.

Respected Advisor
Posts: 3,777

Re: delete the variable that have the same value

Not much going on on SAS-L at all these days, although most of the participants in that thread are still around from time to time.

Ask a Question
Discussion stats
  • 7 replies
  • 490 views
  • 2 likes
  • 4 in conversation