DATA Step, Macro, Functions and more

Deleting Variables When all Values=0

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Deleting Variables When all Values=0

Hi all,

I find a plethora of info on deleting missing values, but I can't seem to figure out how to remove 0's :smileyplain: I want to delete a variable if values from all observations =0. It seems like there would be a simple way to do this, but can't turn anything up. Ideas?

Thanks!


Accepted Solutions
Solution
‎07-18-2011 05:33 PM
PROC Star
Posts: 7,356

Deleting Variables When all Values=0

Why not modify and use the code at: http://support.sas.com/kb/24/622.html ?

Just change the two lines:
if num_vars(i) ne . then num_miss(i)='non-miss';
and if char_vars(i) ne '' then char_miss(i)='non-miss';

to

if num_vars(i) ne 0 then num_miss(i)='non-miss';
and if char_vars(i) ne '0' then char_miss(i)='non-miss';


Art

View solution in original post


All Replies
Solution
‎07-18-2011 05:33 PM
PROC Star
Posts: 7,356

Deleting Variables When all Values=0

Why not modify and use the code at: http://support.sas.com/kb/24/622.html ?

Just change the two lines:
if num_vars(i) ne . then num_miss(i)='non-miss';
and if char_vars(i) ne '' then char_miss(i)='non-miss';

to

if num_vars(i) ne 0 then num_miss(i)='non-miss';
and if char_vars(i) ne '0' then char_miss(i)='non-miss';


Art

PROC Star
Posts: 7,356

Deleting Variables When all Values=0

There was a post here just before I went for dinner and now it has disappeared.  I looked at the code you sent and there was only one line that had to be corrected.

It currently reads:

  /* LIST will contain the list of variables to be dropped.  Ensure  */

  /* it's length is sufficient.                                      */

  length list $ 50;

but, for your data, should read:

  /* LIST will contain the list of variables to be dropped.  Ensure  */

  /* it's length is sufficient.                                      */

  length list $ 200;

Occasional Contributor
Posts: 11

Deleting Variables When all Values=0

Haha yes, sorry, I took that down once I found the same thing and realized it was a stupid question. Thank you so much for your help!! As you saw I modified the code from the site to only look for numeric variables. Worked like a charm. Thanks again!

PROC Star
Posts: 7,356

Deleting Variables When all Values=0

The only stupid question I've ever seen is the one portrayed in the logo at:

http://www.facebook.com/pages/Society-For-Asking-Stupid-Questions/169774899701771

However, it would help if you marked this question as answered so that others don't spend unnecessary time on it.

Super User
Posts: 9,662

Re: Deleting Variables When all Values=0

Your question is very interesting.

How about:

data zero;
input name $ score1-score4;
cards;
peter 10 23 0 65
patrick 23 45 0 65
art 34 56 0 56
sharp 34 65 0 86
;
run;
proc stdize data=zero out=_zero missing=999999 reponly;
run;
proc means data=_zero noprint ;
 var _numeric_;
 output out=drop(drop=_type_ _freq_) sum=;
run; 
data _null_;
 set drop;
 array drop{*} _numeric_;
 array drop_list{200} $ 32 _temporary_; 
 do j=1 to dim(drop) ;
  if drop{j} eq 0 then drop_list{j}=vname(drop{j}); 
 end;
 call symput('drop_var',catx(' ',of drop_list{*}));
 stop;
run;
data want;
 set zero(drop=&drop_var);
run;
data want;
 set want;
 array num{*} _numeric_;
 do j=1 to dim(num) ;
  if num{j} eq 999999 then num{j}=.; 
 end;
run;

Ksharp

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 2161 views
  • 1 like
  • 3 in conversation