|
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;
|