BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jmgorzo
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

5 REPLIES 5
art297
Opal | Level 21

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

art297
Opal | Level 21

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;

jmgorzo
Calcite | Level 5

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!

art297
Opal | Level 21

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.

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 7023 views
  • 2 likes
  • 3 in conversation