Date: Thu, 23 Aug 2007 09:51:20 -0400
Reply-To: Donald Burklo <dwburklo@COPELAND-CORP.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Donald Burklo <dwburklo@COPELAND-CORP.COM>
Subject: Re: Check Dataset for Variable
On Thu, 23 Aug 2007 02:16:17 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Donald ,
>
>Yes there is away to do this:
>
>%Macro VarExist( Lib= , Mem= , Var= ) ;
>/*********************************************/
>/** Name : VarExist **/
>/** **/
>/** Type : Function Style Macro **/
>/** **/
>/** Pupose : This Macro Determines If A Var **/
>/** Exists In A Data Set. **/
>/** **/
>/** Values : 0 ~ Variable Does Is Not In **/
>/** Selected Data Set **/
>/** 1 ~ Variable Is In Selected **/
>/** Data Set **/
>/** **/
>/**Parameters : Lib ~ LibName Of The Data **/
>/** Set **/
>/** Mem ~ Data Set Name **/
>/** Var ~ Name Of A Variable To **/
>/** Look For. Must Be A **/
>/** Valid SAS Variable **/
>/** Name **/
>/*********************************************/
>
>%Local DSID VarNum Close ;
>
>%If ( %SysFunc( Exist( &Lib..&Mem ) ) = 0 ) %Then %Do ;
> %Put ;
> %Put ;
> %Put ERROR: Data Set [ %UpCase(&Lib..&Mem) ] Does Not Exist!!! ;
> %Put ERROR: Please Specify A Valid Data Set. ;
> %Put ;
> %Put ;
> %Return ;
>%End ;
>
>%If ( %Length( %SuperQ(Var) ) = 0 ) %Then %Do ;
> %Put ;
> %Put ;
> %Put ERROR: Parameter Var Is Empty!!! ;
> %Put ERROR: Please Specify A Valid SAS Variable Name. ;
> %Put ;
> %Put ;
> %Return ;
>%End ;
>
>%Let DSID = %Sysfunc( Open ( &Lib..&Mem , IS ) ) ;
>
>
>%If ( &DSID = 0 ) %Then %Do ;
> %Put ;
> %Put ;
> %Put ERROR: Error Trying To Open Data Set ( %UpCase(&Lib..&Mem) ) ;
> %Put ERROR: %SysFunc( SysMsg( ) ) ;
> %Put ;
> %Put ;
> %Return ;
>%End ;
>
>
>%Let VarNum = %Eval( %Sysfunc( VarNum( &DSID , &Var ) ) > 0 ) ;
>
>%Let Close = %SysFunc( Close( &DSID ) ) ;
>
>
>%If ( &Close Ne 0 ) %Then %Do ;
> %Put ;
> %Put ;
> %Put ERROR: Error Trying To Close Data Set ( %UpCase(&DataIn) ) ;
> %Put ERROR: %SysFunc( SysMsg( ) ) ;
> %Put ;
> %Put ;
> %Return ;
>%End ;
>
>
>&VarNum
>%Mend VarExist ;
>
>
>%Put %VarExist( Lib = SASHELP , Mem = CLASS , Var = AGE ) ;
>%Put %VarExist( Lib = SASHELP , Mem = CLASS , Var = ZZZ ) ;
>
>
>
>Toby Dunn
>
>
>Two wrongs are only the beginning.
>
>Success always occurs in private and failure in full view.
>
>Experience is something you don't get until just after you need it.
>
>
>
>
>
>From: Donald Burklo <dwburklo@COPELAND-CORP.COM>
>Reply-To: Donald Burklo <dwburklo@COPELAND-CORP.COM>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Check Dataset for Variable
>Date: Wed, 22 Aug 2007 16:17:53 -0400
>
>Is there a function to check a dataset for a specific variable prior to a
>drop statement?
>
>_________________________________________________________________
>Find a local pizza place, movie theater, and more?.then map the best
route!
>http://maps.live.com/default.aspx?v=2&ss=yp.bars~yp.pizza~yp.movie%
20theater&cp=42.358996~-71.056691&style=r&lvl=13&tilt=-90&dir=0&alt=-
1000&scene=950607&encType=1&FORM=MGAC01
Toby,
Thanks for the response. I would have thought SAS would have a function
for this purpose somewhere.
Don
|