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 (May 2000, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 4 May 2000 17:00:22 -0400
Reply-To:     Richard DeVenezia <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Richard DeVenezia <radevenz@IX.NETCOM.COM>
Organization: MindSpring Enterprises
Subject:      Re: XML Creation Macro

Shawn:

With these types of macros, they don't return values per-se. The act of invoking the macro simply generates 'text' that is replaced in the current token stream being interpreted by the SAS executor.

So when the macro has the &vexist statement, the value of macro variable vexist replaces the %varexist(....).

Hence you can use this feature in several ways

In a macro assignment %let rc = %varexist(...);

In a macro %if (%varexist(...)) %then %do; ... %end;

In a data step if %varexist(...) then do; .... end; Note: In a data step, the value of a data step variable can not be passed to the macro presented by John, since all macros are resolved before the data step is compiled and run. To do checks on tables and variables that are values of variables in a data set, use the same functions ( open, close, varnum ) as the macro does.

You could even get funky and write a macro that is for use in data step only. e.g. (untested) %macro dshasvar (dataset, variable); %* generates data step code for use only in data step; %* dataset - character: name of data set to examine; %* variable - character: name of variable to check for in data set; %* arguments are quoted text strings or data step character expressions;

%* your data step should not have variables dsid or vexist, if so this macro will clash; dsid= open( &dataset ); if dsid then do; vexist=varnum( dsid, &varname ); dsid=close( dsid ); end; else vexist=0; %mend;

sample use: data whatever; set fromthat; %dsHasVar (trim(libname)||'.'||memname, name); if vexist then ...

%dsexist ('SASUSER.CRIME', 'PUNISH'); if vexist then ... run;

"Shawn Ribordy" <pndswimming@hotmail.com> wrote in message news:3911B1DD.36ADABE3@hotmail.com... > John, This macro seems to work great, but I can't figure out how to test the > return value. > > I tried > %VAREXIST(TESTDATA, TESTVAR); > IF &VEXIST NE 0 THEN DO; > ETC... > END; > > Please help: > > John Iwaniszek wrote: > > > see the following. > > > > /* This is a collection of macros that retrieve information about a > > variety of > > variable attributes within a given sas data set. > > > > varexist Returns 0 if varname does not exist in data set > > inset, > > >0 otherwise. > > > > jri 1/11/98 12:06PM > > s > > */ > > > > %macro varexist( inset, varname ); > > %local > > vexist > > ; > > %let dsid=%sysfunc( open( &inset, i)); > > %if &dsid %then %do; > > %let vexist=%sysfunc( varnum( &dsid, &varname)); > > %let rc=%sysfunc( close( &dsid)); > > %end; > > > > &vexist > > > > %mend varexist; > > > > Shawn Ribordy wrote: > > > > > > I am trying to write a SAS macro that will output XML in a DATA _NULL_ > > > step. I want to build the macro so it can handle up to 150 different > > > variables and corresponding XML tags, but I won't necessarily use all of > > > them when I call the macro. I only want to output the XML tags and > > > variable if the variable exists. > > > > > > Is there a way to test whether or not a variable is in a dataset without > > > generating an error? > > > > > > IF FCTYNO THEN DO; > > > etc.... > > > END; > > > > -- > > John Iwaniszek > > > > Statistical Programming Manager > > Stat-Tech Services, LLC > > > > 919 571 6444 > > > > Developers of the Macro Reporting System - Delivering > > Statistical reports in ASCII, RTF, and HTML > > > > http://www.StatTechServices.com >


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