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 (June 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 29 Jun 2004 09:18:08 -0500
Reply-To:     "Dunn, Toby" <tdunn@TEA.STATE.TX.US>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Dunn, Toby" <tdunn@TEA.STATE.TX.US>
Subject:      Re: Macro Variable Problem
Comments: To: "Ross, Michael D" <michael.ross@ASTRAZENECA.COM>
Content-Type: text/plain; charset="iso-8859-1"

As I am still a little fuzzy on what is a macro variable and what is a data variable in your problem I'll go through several scenarios for you.

Data variable against data variable;

Data one; Set whatever; If x = y then flag = 1; Run;

Data variable against macro variable;

%let y = ahjks.hhjk;

data one; set whatever; if x = "&y"; run;

macro variable against macro variable;

%macro one;

%if &x = &y %then %let flag = 1; %mend one;

finally Macro variable created from a dataset against a data set variable;

data _null_; set whatever; call symput ('y', y); run;

data one; set another_dataset; if x = "&y" then flag = 1; run;

The online help docs state: " The %STR and %NRSTR functions mask a character string during compilation of a macro or macro language statement. They mask the following special characters and mnemonic operators:

+ - * / < > = ¬ ^ ~ ; , blank AND OR NOT EQ NE LE LT GE GT

They also mask the following characters when they occur in pairs and when they are not matched and are marked by a preceding % :

' " ( )

In addition, %NRSTR also masks the following characters:

& %"

and %nrbquote: The %BQUOTE and %NRBQUOTE functions mask a character string or resolved value of a text expression during execution of a macro or macro language statement. They mask the following special characters and mnemonic operators:

' " ( ) + - * / < > = ¬ ^ ~ ; , blank AND OR NOT EQ NE LE LT GE GT

In addition, %NRBQUOTE masks

& %

%NRBQUOTE is most useful when the resolved value of an argument may contain

strings that look like macro variable references but are not, so the macro processor should not attempt to resolve them when it next encounters them.

macro invocations that you do not want the macro processor to attempt to resolve when it next encounters them.

Note: The maximum level of nesting for the macro quoting functions is 10.

--------------------------------------------------------------------------------

Tip

You can use %BQUOTE and %NRBQUOTE for all execution-time macro quoting because they mask all characters and mnemonic operators that can be interpreted as elements of macro language. Quotation marks (' " ) do not have to be marked. Parentheses (( ) ) must match in the text supplied to these functions."

I don't see were you would need either one of them in your case. Now if it is the case that you have unequal quotes or and ampersand that you want masked then you would need to use one or both of these.

HTH Toby Dunn

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ross, Michael D Sent: Tuesday, June 29, 2004 8:42 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Macro Variable Problem

Thanks. With %nrstr - I'm trying to mask any extraneous characters that could be in &var. I'm not to sure what the best approach is. I need to evaluate &var against xxxxxx to see if .C exists as a value then set mis_flg=1 if it does. I don't want to mask the '.' - Is there a way to have Sas mask other extraneous character except the '.' - The '.' is always the first byte of the string.

Hope this makes sense! Mike

-----Original Message----- From: Dunn, Toby [mailto:tdunn@tea.state.tx.us] Sent: Tuesday, June 29, 2004 9:23 AM To: Ross, Michael D; SAS-L@LISTSERV.UGA.EDU Subject: RE: Macro Variable Problem

The way you have it written it should only resolve to cvar1 or cvar2. remember that macro variables are only text, thus you are giving macro variable "var" the text value of cvar1 or cvar2 not a reference to a macro variable cvar1 or cvar2. So you will either need to give macro variable "var" &cvar1 or &cvar2, or you will need to add two ampersands to (&var) in your code. By the way why do you have %nrstr in your code?

HTH Toby Dunn

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ross, Michael D Sent: Monday, June 28, 2004 4:08 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Macro Variable Problem

Hi All, I can't get the &VAR to resolve to it's value. It resolves to cvar1 (the name of the variable being passed). Any suggestions?

Mike

%let out1='aaaaaaa'; %let out2='bbbbbbb';

%macro mismr(out1='', out2='');

%local CVAR1 AZ_CVAR2; call symput('CVAR1',trim(&out1)); call symput('CVAR2',trim(&out2));

rc1 = %mcomr(cvar1); rc2 = %mcomr(cvar2); %mend mismr;

%macro mcomr(var);

%let mis_len = %length(&misn);

%do i = 1 %to &mis_len %by 3; %if %nrstr(&var) eq %nrbquote(%substr(xxxxxx, &i, 2)) %then %let mis_flg = 1; /* THIS IS WHERE I'M HAVING A PROBLEM*/ %end; %mend mcomr;


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