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 (January 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 14 Jan 2004 17:35:49 GMT
Reply-To:     bogdan romocea <br44092@GAWAB.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         bogdan romocea <br44092@GAWAB.COM>
Subject:      Re: save dataset contents as string
Comments: To: Tim Wade <wade_tj@YAHOO.COM>
In-Reply-To:  <20040114164846.46060.qmail@web12306.mail.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"

First use PROC CONTENTS with ODS OUTPUT and get the output data set that contains the names of all the variables. Then do something like this:

/*names of variables into macro variables*/ data _null_; set /*your data set*/ nobs=nvars; call symput('var'||trim(left(put(_n_,8.))),trim(left(/*name of column with variable names*/))); call symput('nvars',trim(left(nvars))); run;

/*then spit all those names as a string*/ %macro string; %do i=1 %to %eval(&nvars);&&var&i %end; %mend string; /*your final string here*/ %let strg=%string;

That's it.

Tim Wade writes:

> Dear SAS experts and enthusiasts: > > I would like to save the names of all the variables in > a SAS dataset as a string so that I can save it as a > macro variable and use it in other functions. Is there > an easy way to do this? > > For example: > > %let varlist="LIST OF VARIABLE NAMES IN DATA SET > TEST1"; > data test1; > set test1; > if index(&varlist, xxx)>1 then do; > stuff > more stuff > end; > run; > > Thanks much for any assistance or suggestions > > Tim > > ===== > wade_tj@yahoo.com > > __________________________________ > Do you Yahoo!? > Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes > http://hotjobs.sweepstakes.yahoo.com/signingbonus

________________________________ 15 Mbytes Free Web-based and POP3 Sign up now: http://www.gawab.com


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