SYSPARM: MACRO v Data Step question

SYSPARM: MACRO v Data Step question

Post by Don W. Bro » Sat, 07 Oct 2000 04:00:00



Greetings SAS-L,

Logic and/or knowledge evaporated.

I'm using SYSPARM to pass a value (SYSPARM=1-8 characters) from which I want
to determine whether a PROC Step will be run or not. If the value is EXACTLY
0000 (4 zeros) the MACRO should generate the PROC Step for execution later
in the job; if anything else it would just %PUT a message indicating that
the PROC was bypassed.

Some testing (LOG output below) seems to reveal some difference in handling
between within a macro (at least as I have done it) and in open code. The
data step method seems to make sense to me but the macro handling doesn't.
Could someone please set me straight here?

Thanks in advance,

Don Brown
DBA
U.S. Government Printing Office
202.512.0119


NOTE: This session is executing on the WIN_98  platform.

NOTE: SAS initialization used:
      real time           2.74 seconds

1    %macro prm;
2      %if &sysparm^=0000 %then
3          %put NE within Macro;
4      %else
5          %put EQ within Macro;
6    %mend prm;
7    %prm
MLOGIC(PRM):  Beginning execution.
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
MLOGIC(PRM):  %IF condition &sysparm^=0000 is FALSE
MLOGIC(PRM):  %PUT EQ within Macro
EQ within Macro
MLOGIC(PRM):  Ending execution.

8    Data _NULL_;
9    If sysparm()^='0000' then put 'NE using sysparm()';
10     else put 'EQ using sysparm()';
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
11   If "&sysparm" ^= '0000' then put 'NE using &sysparm';
12     else put 'EQ using &sysparm';
13   parmsize=length("&sysparm");
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
14   Parm="&sysparm";
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
15   If parm^='0000' then put 'NE using  parm';
16     else put 'EQ using parm';
17   Put parmsize= Parm= "&sysparm";
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
18   Run;

NE using sysparm()
NE using &sysparm
NE using  parm
parmsize=6 Parm=000000 000000
NOTE: DATA statement used:
      real time           0.05 seconds

75   %macro prm;
76     %if &sysparm^='0000' %then
77         %put NE within Macro;
78     %else
79         %put EQ within Macro;
80   %mend prm;
81   %prm
MLOGIC(PRM):  Beginning execution.
SYMBOLGEN:  Macro variable SYSPARM resolves to 0000
MLOGIC(PRM):  %IF condition &sysparm^='0000' is TRUE
MLOGIC(PRM):  %PUT NE within Macro
NE within Macro
MLOGIC(PRM):  Ending execution.
82   %macro prm;
83     %if &sysparm^='0000' %then
84         %put NE within Macro;
85     %else
86         %put EQ within Macro;
87   %mend prm;
88   %prm
MLOGIC(PRM):  Beginning execution.
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
MLOGIC(PRM):  %IF condition &sysparm^='0000' is TRUE
MLOGIC(PRM):  %PUT NE within Macro
NE within Macro
MLOGIC(PRM):  Ending execution.

 
 
 

SYSPARM: MACRO v Data Step question

Post by Jonathan Goldbe » Wed, 11 Oct 2000 04:00:00


Don W. Brown asks a question concerning macro &sysparm handling (see message
below).

The problem here is actually about macro comparisons.  From the V8 Macro
Language Reference:

 SAS Macro Language: Reference

 Comparing Numeric Operands in Logical Expressions

When the macro processor evaluates logical expressions that contain operands
that represent numbers, it converts the characters temporarily to numeric
values.

As it happens, the values Mr. Brown is passing via the SYSPARM facility are all
zeros.  The macro comparison is therefore numeric.

This behavior can be circumvented by comparing lengths or appending a
non-numeric character to both comparison strings.

Jonathan

------------------  Original Message Seperator --------------------------

Date:    Fri, 6 Oct 2000 15:12:15 -0400

Subject: SYSPARM:  MACRO v Data Step question

Greetings SAS-L,

Logic and/or knowledge evaporated.

I'm using SYSPARM to pass a value (SYSPARM=1-8 characters) from which I want
to determine whether a PROC Step will be run or not. If the value is EXACTLY
0000 (4 zeros) the MACRO should generate the PROC Step for execution later
in the job; if anything else it would just %PUT a message indicating that
the PROC was bypassed.

Some testing (LOG output below) seems to reveal some difference in handling
between within a macro (at least as I have done it) and in open code. The
data step method seems to make sense to me but the macro handling doesn't.
Could someone please set me straight here?

Thanks in advance,

Don Brown
DBA
U.S. Government Printing Office
202.512.0119


NOTE: This session is executing on the WIN_98  platform.

NOTE: SAS initialization used:
      real time           2.74 seconds

1    %macro prm;
2      %if &sysparm^=0000 %then
3          %put NE within Macro;
4      %else
5          %put EQ within Macro;
6    %mend prm;
7    %prm
MLOGIC(PRM):  Beginning execution.
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
MLOGIC(PRM):  %IF condition &sysparm^=0000 is FALSE
MLOGIC(PRM):  %PUT EQ within Macro
EQ within Macro
MLOGIC(PRM):  Ending execution.

8    Data _NULL_;
9    If sysparm()^='0000' then put 'NE using sysparm()';
10     else put 'EQ using sysparm()';
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
11   If "&sysparm" ^= '0000' then put 'NE using &sysparm';
12     else put 'EQ using &sysparm';
13   parmsize=length("&sysparm");
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
14   Parm="&sysparm";
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
15   If parm^='0000' then put 'NE using  parm';
16     else put 'EQ using parm';
17   Put parmsize= Parm= "&sysparm";
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
18   Run;

NE using sysparm()
NE using &sysparm
NE using  parm
parmsize=6 Parm=000000 000000
NOTE: DATA statement used:
      real time           0.05 seconds

75   %macro prm;
76     %if &sysparm^='0000' %then
77         %put NE within Macro;
78     %else
79         %put EQ within Macro;
80   %mend prm;
81   %prm
MLOGIC(PRM):  Beginning execution.
SYMBOLGEN:  Macro variable SYSPARM resolves to 0000
MLOGIC(PRM):  %IF condition &sysparm^='0000' is TRUE
MLOGIC(PRM):  %PUT NE within Macro
NE within Macro
MLOGIC(PRM):  Ending execution.
82   %macro prm;
83     %if &sysparm^='0000' %then
84         %put NE within Macro;
85     %else
86         %put EQ within Macro;
87   %mend prm;
88   %prm
MLOGIC(PRM):  Beginning execution.
SYMBOLGEN:  Macro variable SYSPARM resolves to 000000
MLOGIC(PRM):  %IF condition &sysparm^='0000' is TRUE
MLOGIC(PRM):  %PUT NE within Macro
NE within Macro
MLOGIC(PRM):  Ending execution.

 
 
 

1. v8.2 macro question - passing the contents of a data step variabl e to a macro

Listers:

In v8.2, is it possible to invoke a macro within a data step and pass to the
macro the contents of a data step variable defined within that datastep?
Note that the following silliness is for illustration only, the real macro
has some meat that requires it to be a macro.

e.g.
%global other;
%macro dumb_macro(stuff);
    %let other = %scan(&stuff,1,'/');
%mend;

data harry;
   input 'c:\test.txt';
   input var1 var2 var3;
   %dumb_macro(var1);  /* passes the literial 'var1' rather than contents of
var1 */
   var4 = "&other";
run;

Adding call symput( ) doesn't help since the symput'ed variable isn't
available until the data step completes.

Am I destined to do something like the following:

data harry;
   retain x 0;
   infile 'c:\blah.txt' end=eof;
   input var1 var2 var3;
   call symput('var'||trim(left(x)),var1);
   if eof then call symput('limit',x);
run;

%macro loop;
%local x;
data second;
 %do x = 1 %to &limit;
     %dumb_macro(&&var&x);
      var4 = "&other";
      output;
   %end;
run;
%mend loop;
%loop;

then merge datasets 'harry' and 'second'.

TIA

2. Voice over Frame Relay & Packet Shapping

3. v8.2 macro question - passing the contents of a data step var iable to a macro

4. NASA report

5. A question about macro invocation within data step

6. receive COM port data per interrupt

7. v8.2 macro question - passing the contents of a data step

8. LONDON - Corba3 - OrbixOTM3/OrbixStudio/RTCorba/Java/XML/C++ - Derivatives System

9. Question on usage of data conversion functions in a Data Step ;

10. Question on usage of data conversion functions in a Data Step;

11. run macro in data step

12. How to assign a data step character value to a macro var

13. MACRO in DATA STEP.