| Date: | Thu, 28 Jun 2007 22:28:41 +0000 |
| Reply-To: | toby dunn <tobydunn@HOTMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | toby dunn <tobydunn@HOTMAIL.COM> |
| Subject: | Re: macro scope |
|
| In-Reply-To: | <1183065488.987607.165340@w5g2000hsg.googlegroups.com> |
| Content-Type: | text/plain; format=flowed |
|---|
Mindy ,
You have used a form of commenting text that is less than optimal. You
should use /* */
It doesnt get compiled like * ABC ; does. Now what implication does that
have to your question well you have a comment with a unmatch single quote in
it. Since it is compiled it SAS sees the single quote and wants another
one. It cant find one so every thing including your %Mend statement is seen
as part of a quoted text.
So yank the single quote out or changeyour comments to /* */.
Better yet why are you doing this why not do something like:
Data Need ;
If _N_ = 0 Then Call Missing( C , D ) ;
Set Test ;
Run ;
It will set the variables C and D to missing and if they exist it wont do a
thing if they dont exist they will be created. The one thing you will have
to watch is if C and/or D is a character value. Which means you have to
define their length before the If statement.
Toby Dunn
If anything simply cannot go wrong, it will anyway. Murphys Law #2.
The buddy system is essential to your survival; it gives the enemy somebody
else to shoot at.
Murphys Law #
Tell a man there are 300 billion stars in the universe and he'll believe
you. Tell him a bench has wet paint on it and he'll have to touch to be
sure. Murphys Law #9
From: Mindy <master2005_sas@YAHOO.COM>
Reply-To: Mindy <master2005_sas@YAHOO.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: macro scope
Date: Thu, 28 Jun 2007 14:18:08 -0700
Hey, Guys,
I have two sas codes as below. The first one gave the results I
expected, and the second one gave me the warning as "missing %mend
statement." The only difference of these two codes are the start point
of a macro. I couldn't figure out why the second code doesn't work.
Could someone give a highlight of the problem? Thanks a lot.
(1) program source code
options mlogic mprint symbolgen;
data test;
input a b;
cards;
1 2
3 4
;
run;
*** check if variable c and d exist in dataset test;
data _null_;
dsid=open("test");
check1=varnum(dsid, 'c');
check2=varnum(dsid, 'd');
if check1=0 then call symput('ex_c','0');
if check2=0 then call symput('ex_d','0');
run;
*** resign variable c and d to missing if they don't exist in dataset
test;
%macro try;
data test;
set test;
%if &ex_c=0 %then c=.;;
%if &ex_d=0 %then d=.;;
run;
%mend try;
%try
proc print data=test;
run;
************************
Program output is ,
The SAS System 14:01 Thursday, June 28, 2007 1
Obs a b
c d
1 1
2 . .
2 3
4 . .
(2) Program source code
options mlogic mprint symbolgen;
data test;
input a b;
cards;
1 2
3 4
;
run;
*** check if variable c and d exist in dataset test;
%macro try;
data _null_;
dsid=open("test");
check1=varnum(dsid, 'c');
check2=varnum(dsid, 'd');
if check1=0 then call symput('ex_c','0');
if check2=0 then call symput('ex_d','0');
run;
*** resign variable c and d to missing if they don't exist in dataset
test;
data test;
set test;
%if &ex_c=0 %then c=.;;
%if &ex_d=0 %then d=.;;
run;
%mend try;
%try
proc print data=test;
run;
******program log,
WARNING: Missing %MEND statement
_________________________________________________________________
PC Magazine’s 2007 editors’ choice for best Web mail—award-winning Windows
Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507
|