Date: Thu, 15 Mar 2001 21:21:15 -0800
Reply-To: maxsfolks <maxsfolks@EMAIL.MSN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: maxsfolks <maxsfolks@EMAIL.MSN.COM>
Subject: Re: keep = variable list
I work with datasets that have hundreds (some thousands) of variables, and
I've developed a method for constructing code with PROC CONTENTS and 'PUT'
statements. This method saves me time, and reduces coding errors. I hope
you will find it useful. My example uses KEEP VARLIST, instead of KEEP=
VARIABLE LIST. I don't know if that will make a difference in your
situation. This untested example was derrived from a working program.
A cool thing about this method is that you can select by characteristics of
the variable labels, or formats as well. It's also possible to use the
method to write programs which can identify and incorporate new variables,
no matter where they are added.
I'm sure this is not an original idea, and I'd be interested to hear from
others in the newsgroup who care to share their favorite methods for writing
'dynamic code'. Perhaps someone has an ARRAY trick that is easier.
Biostatistical Core Unit
Iowa Mental Health Clinical Research Center
/* begin dynamic coding: run contents and output results as a dataset */
proc contents data=yourdata
proc sort data=tmp;
data codeit; length revname $8;
/* an easy way to locate varnames ending w/zero is to use the reverse
/* this is the key */
/* select only variables ending with zero */
/* output to an ASCII file with the .sas extension */
/* construct the first line of code, and begin the keep statment */
if count=1 then do;
put "data next; set yourdata; keep ";
/* now construct the list of variable names that end in zero */
/* and don't forget to add the semicolon in quotes. */
put name||";" ;
/* the program is saved to c:\keeplist.sas */
/* now include the program */
Renaud Harduin <firstname.lastname@example.org> wrote in message
> Hi SAS-L,
> I want to do a keep = dataset option. My variables are formed like this
> Q1A0 --> Q12A0
> B1A0 --> Q12A0
> Q1A_1--> Q12A_1
> B1A0 --> Q12A_1
> I just want to keep the variable wich end with a 0. I know some tips like
> or A1 - A12 to retrieve a list without typing every variable name.
> Do you have a tip to specify a list based on suffix xxxA0 ?