Date: Wed, 16 Nov 2011 12:58:51 -0500
Reply-To: "Bian, Haikuo" <HBian@FLQIO.SDPS.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Bian, Haikuo" <HBian@FLQIO.SDPS.ORG>
Subject: Re: extract data from a large raw datafile
In-Reply-To: <201111161559.pAGBnVSf003157@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
I am sorry that I am not aware of any proc will do directly what you want. So let 's go back to good old datastep.
Since drop statement (or option drop=) is declare statement, it can't be executed conditionally. Therefore you will generally need two data steps to accomplish your goal. Although, you can certainly cheat by invoking call execute like the code below:
data have;
infile cards;
input Site Sp1 Sp2 Sp3 Sp4;
cards;
1 2 0 1 0
1 0 0 3 0
2 5 6 0 0
2 0 1 1 0
;
data want1 ;
do until (last.site);
set have (where=(site=1));
retain _dp;
length _dp $40;
by site;
array sp sp1-sp4;
array _sp _sp1-_sp4;
if first.site then
do;
do i=1 to dim(sp);
_sp(i)=0;
end;
end;
do i=1 to dim(sp);
_sp(i)+sp(i);
end;
end;
do i=1 to dim(sp);
if _sp(i)=0 then _dp=catx(' ',strip(_dp),vname(sp(i)));
end;
call symput('_dp',_dp);
call execute("data want; set have (where=(site=1));drop &_dp;run;");
run;
proc print;run;
Best Regards,
Haikuo
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nabaneeta Saha
Sent: Wednesday, November 16, 2011 11:00 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: extract data from a large raw datafile
Hello,
I have a dataset with more than 200 variables which are all species names,
and another variable which denotes their site of collection (more than 30
sites).
Site Sp1 Sp2 Sp3
1 2 0 1
1 0 0 3
2 5 6 0
2 0 1 1
I want to extract out data for a particular site, only with the species
which are present in that site, (I want only those species the sum of which
is not 0), for a particular site, for ex. I want a table like this
Site Sp1 Sp3
1 2 1
1 0 3
Which proc should I use for this?
Thanks for your help!
nsaha6
-----------------------------------------
Email messages cannot be guaranteed to be secure or error-free as
transmitted information can be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The
Centers for Medicare & Medicaid Services therefore does not accept
liability for any error or omissions in the contents of this
message, which arise as a result of email transmission.
CONFIDENTIALITY NOTICE: This communication, including any
attachments, may contain confidential information and is intended
only for the individual or entity to which it is addressed. Any
review, dissemination, or copying of this communication by anyone
other than the intended recipient is strictly prohibited. If you
are not the intended recipient, please contact the sender by reply
email and delete and destroy all copies of the original message.