LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2001, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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

Renaud,

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.

Regards,

Bill McKirgan, Data Manager Biostatistical Core Unit Iowa Mental Health Clinical Research Center

/* begin dynamic coding: run contents and output results as a dataset */

proc contents data=yourdata out=tmp; run;

proc sort data=tmp; by name; run;

data codeit; length revname $8; set tmp; by name; count=_n_;

/* an easy way to locate varnames ending w/zero is to use the reverse function */ /* this is the key */

revname=reverse(name);

/* select only variables ending with zero */

if substr(revname,1,1)="0";

/* output to an ASCII file with the .sas extension */

file='c:\keeplist.sas';

/* construct the first line of code, and begin the keep statment */

if count=1 then do; put "data next; set yourdata; keep "; end;

/* now construct the list of variable names that end in zero */ /* and don't forget to add the semicolon in quotes. */

put name||";" ;

run;

/* the program is saved to c:\keeplist.sas */

/* now include the program */

%include 'c:\keeplist.sas'; run;

Renaud Harduin <r.harduin@abs-technologies.com> wrote in message news:98oobt$cim$1@fenris.isp.9tel.net... > 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 Q: > 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 ? > > Thanks > >


Back to: Top of message | Previous page | Main SAS-L page