Date: Thu, 30 Oct 2008 14:14:28 -0500
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: Test if a var is available inside data step?
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
You could query the data dictionary on that variable, like this:
proc sql;
select count(name)
into :count1
from dictionary.columns
where memname='CHISQ_SET' and
libname='WORK'
and name='TABLE';
quit;
%put &count1;
%if &count1= 0 %then ...
-Mary
----- Original Message -----
From: Ya Huang
To: SAS-L@LISTSERV.UGA.EDU
Sent: Thursday, October 30, 2008 1:52 PM
Subject: Test if a var is available inside data step?
Hi there,
%macro cat(v1=,v2=,v3=);
&v3=trim(&v1)||trim(&v2);
%mend cat;
*first call is OK;
data xx;
set sashelp.class (obs=1);
%cat(v1=sex,v2=name,v3=sname);
run;
proc print;
run;
*second call failed, because name is not available;
data yy;
set sashelp.class (obs=1 drop=name);
%cat(v1=sex,v2=name,v3=sname);
run;
proc print;
run;
What I want is somehow add test in the macro, so that if v2
is not available, then switch to
&v3=trim(&v1)||trim(&v2);
to
&v3=trim(&v1);
The message like "NOTE: Variable name is uninitialized" should
be avoided too.
Thanks
Ya