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!
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
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
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;
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!
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.
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
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.
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.