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 (July 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 9 Jul 2007 06:39:35 -0700
Reply-To:   chris@OVIEW.CO.UK
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   chris@OVIEW.CO.UK
Organization:   http://groups.google.com
Subject:   Re: concatenate macro variable
Comments:   To: sas-l@uga.edu
In-Reply-To:   <1183983808.694925.112730@r34g2000hsd.googlegroups.com>
Content-Type:   text/plain; charset="us-ascii"

Dirk,

You're mixing data step code and macro code, which is almost always a mistake. You can't make a %let statement (macro code) conditional using an if statement (data step code). Try running your macro with "options mprint" turned on, and look at the code that your macro generates - you'll see it's not at all what you want. Use Elvis to make viewing the MPRINT code easier (Views -> MPRINT only).

Also, you don't need the first double ampersand in the %let statement - one is enough - but as the %let shouldn't be there at all, it's not worth fixing.

To modify a macro variable's value using data step code, look up CALL SYMPUT and SYMGET. This would be a first step:

if &&var&i>0 then call symput('keep1', trim(symget('keep1')) || ' &&var&i');

but that would still be a very sub-optimal solution.

Chris. -------------------------------------------------------- Elvis SAS Log Analyser - http://www.oview.co.uk/elvis Recover runnable SAS code from your log's MPRINT lines. --------------------------------------------------------

On 9 Jul, 13:23, Dirk Nachbar <dirk...@googlemail.com> wrote: > Hi > > I want to create a macro variable with all variables names whose only > value is bigger than zero (the input is from proc means). Below is the > macro, unfortunately at the moment all possible variables get selected > (ie keep=var1 to var&num_vars), although not all are above 0. Any > ideas? > > &&var&i is pre-defined. > > Dirk > > %macro keep; > %let keep1=; > data _null_; > set sums; > %do i=1 %to &num_vars; > /*create a string with the variables to keep*/ > if &&var&i>0 then %let keep1=&&keep1 &&var&i;; > > %end; > run; > > data fggf; > set gffdfdas (keep=ddfs &&keep1); > run; > %mend; > %keep;


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