Date: Sun, 18 Dec 2005 20:51:06 -0500
Reply-To: Ya Huang <ya.huang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ya Huang <ya.huang@AMYLIN.COM>
Subject: Re: Need help on a simple data manipulation question
Always keep in mind that good data structure makes better program.
Your problem can be resolved easily when the data is transposed:
data tran /view=tran;
set test;
array vy y:;
do over vy;
vnm=vname(vy);
val=vy;
output;
end;
keep x vnm val;
run;
proc sql noprint;
select distinct vnm into : droplst separated by ' '
from tran
group by x, vnm
having count(val)=.
;
%put &droplst;
data test1;
set test (drop=&droplst);
run;
proc print;
run;
Obs x y1 y4
1 1 3 90
2 1 2 10
3 1 2 8
4 2 1 8
5 2 3 .
6 2 4 9
7 3 9 4
8 3 8 5
HTH
Ya
On Sun, 18 Dec 2005 16:25:22 -0800, Jason Shen <jason80115@YAHOO.COM> wrote:
> Hi,
>
> I need help on a simple data manipulation question. For example, I have
the following data set.
>
> data test;
> input x y1 y2 y3 y4 y5;
> cards;
> 1 3 * 5 90 9
> 1 2 * 9 10 *
> 1 2 * 8 8 6
> 2 1 3 * 8 10
> 2 3 8 * * 9
> 2 4 2 * 9 3
> 3 9 2 9 4 *
> 3 8 1 2 5 *
> ;
> If any one of variables y1-y5 does not have any non-missing values for
each value of x, this variables should be removed from the dataset. So in
this case, y2 is all missing for x=1; y3 is all missing for x=2 and y5 is
all missing for x=3. I want to remove variables y2, y3 and y5 from the
data set. Since I actually have 50 variables in my real data, I want to
know how to write the code to remove the variables I don't want.
> the final data shoud look like this:
> 1 3 90
> 1 2 10
> 1 2 8
> 2 1 8
> 2 3 *
> 2 4 9
> 3 9 4
> 3 8 5
> Thanks a lot.
>
> Jason
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam? Yahoo! Mail has the best spam protection around
>http://mail.yahoo.com