| Date: | Wed, 7 Jul 2010 18:42:31 +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: Variables ending in a string |
|
| In-Reply-To: | <OF3466FBED.63DDCB72-ON86257759.00647680-86257759.0064D2DD@fd9ns01.okladot.state.ok.us> |
| Content-Type: | text/plain; charset="iso-8859-1" |
Short answer NO!!!
Longer Answer Use this:
Macro VarMatch( DSN = , Pattern = , PRX= ) ;
/*****************************************************************************/
/** Macro Name : VarMatch **/
/** **/
/** **/
/** Purpose : Returns A List Of Variables From A Data Set That Matches A **/
/** Given Pattern. **/
/** **/
/** Parameters : DSN ~ Data Set To Get Variables From. It Can Be Either **/
/** Just A Member Name Which Cause The Macro To Look **/
/** In The Work Directory Or A Two Level Name. **/
/** **/
/** Pattern ~ Is A Simple Pattern Where The User Gives The **/
/** Known Letters in The Variables Name Seperate By **/
/** * For Those They Do Not. **/
/** Examples: ABC* = All Vars That Start With ABC **/
/** *ABC = All Vars That End With ABC **/
/** A*C = All Vars That Start With A And **/
/** End With C. **/
/** **/
/** PRX ~ Is A Perl Regular Expression. This Is Designed For **/
/** Advanced Users Who Fully Understand RegEx. **/
/** **/
/** Created By: Toby Dunn ***************** **/
/** Created On: 03/12/2008 * Make It Right * **/
/** ***************** **/
/*****************************************************************************/
%Local DSID VarNum I VarName Pattern VarList Close ;
%If ( %Length(&DSN) EQ 0 ) %Then %Do ;
%Put ;
%Put ;
%Put ERROR: The DSN Parameter Is Empty. ;
%Put ERROR: Please Specify A Valid Value. ;
%Put ;
%Put ;
%Return ;
%End ;
%If ( %SysFunc( Exist( &DSN ) ) EQ 0 ) %Then %Do ;
%Put ;
%Put ;
%Put ERROR: The Data Set [&DSN] Does Not Exist!!! ;
%Put ERROR: Please Check The Value Of DSN= Parameter ;
%Put ;
%Put ;
%Return ;
%End ;
%If ( %Length( &Pattern ) EQ 0 ) And
( %Length( &PRX ) EQ 0 ) %Then %Do ;
%Put ;
%Put ;
%Put ERROR: There Is No Pattern Or RegEx To Match. ;
%Put ERROR: Please Specify A Valid Value For Pattern Or PRX. ;
%Put ;
%Put ;
%Return ;
%End ;
%If ( %Length( &Pattern ) GT 0 ) And
( %Length( &PRX ) GT 0 ) %Then %Do ;
%Put ;
%Put ;
%Put NOTE: A Value Was Given For Both Pattern And PRX. ;
%Put NOTE: The PRX RegEx Will Be Used. ;
%Put ;
%Put ;
%End ;
%Let DSID = %Sysfunc( Open( &DSN , I ) ) ;
%If ( &DSID EQ 0 ) %Then %Do ;
%Put ;
%Put ;
%Put ERROR: Data Set [&DSN] Could Not Be Opened. ;
%Put %SysFunc( SysMSG() ) ;
%Put ;
%Put ;
%End ;
%Let VarNum = %SysFunc( AttrN( &DSID , NVars ) ) ;
%If ( &VarNum EQ 0 ) %Then %Do ;
%Put ;
%Put ;
%Put ERROR: Data Set [&DSN] Has No Variables. ;
%Put ;
%Put ;
%End ;
%If ( %Length( &PRX ) > 0 ) %Then %Do ;
%Let Pattern = %SysFunc( PRXParse( &PRX ) ) ;
%End ;
%Else %Do ;
%Let Pattern = %SysFunc( TranWrd( &Pattern , * , .* ) ) ;
%Let Pattern = %SysFunc( PRXParse( /^&Pattern$/i ) ) ;
%End ;
%Do I = 1 %To &VarNum ;
%Let VarName = %Sysfunc( VarName( &DSID , &I ) ) ;
%If ( %SysFunc( PRXMatch( &Pattern , &VarName ) ) > 0 ) %Then %Do ;
%Let VarList = &VarList &VarName ;
%End ;
%End ;
%Let Close = %SysFunc( Close( &DSID ) ) ;
%If ( %Length( &VarList ) EQ 0 ) %Then %Do ;
%Put ;
%Put ;
%Put NOTE: Could Not Find A Variable That Matched Pattern. ;
%Put ;
%Put ;
%End ;
&VarList
%Mend VarMatch ;
Toby Dunn
"Don't bail. The best gold is at the bottom of barrels of crap."
Randy Pausch
"Be prepared. Luck is where preparation meets opportunity."
Randy Pausch
> Date: Wed, 7 Jul 2010 13:21:15 -0500
> From: mpajoh@ODOT.ORG
> Subject: Variables ending in a string
> To: SAS-L@LISTSERV.UGA.EDU
>
> is there a short hand for listing the variables:
> e.g.:
>
> var invcost factcost custcost wholecost . . . ;
>
> something like :cost?
>
> Thanks,
>
> Masoud
_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4 |