Date: Thu, 8 Jul 1999 23:46:01 +0100
Reply-To: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Subject: Re: Q: format exists?
In-Reply-To: <3783C3AB.1908@capitale.qc.ca>
Although Bernard Tremblay's solution is just what the original poster
wanted, I was hoping to find something general enough to cope with the
environment defined by all catalogs referred by option FMTSEARCH
Until the v7/8 logical catalog concatenation, wouldn't we have to test
for existence of the format in work, library.formats and any catalog of
the fmtsearch libraries ?
Bernard Tremblay <bernard@CAPITALE.QC.CA> writes
>Hi,
>
> How about the following one liner macro for testing existence of a
>character/numeric format ?
>
>%macro existfmt(fmt);
> %eval(%SYSFUNC(CEXIST(WORK.FORMATS.&fmt..FORMAT,U)) +
>%SYSFUNC(CEXIST(WORK.FORMATS.&fmt..FORMATC,U)));
>%mend;
>
>
> It will return a 1 if the format exist or 0 if not but does'nt tell you
>if it's a character
> neither a numeric format.
>
> Tested on a SunOS with SAS 6.12 TS020. But it shall work on any OS.
>
> It has the advantage to incorporate into any regular/scl/macro
>statement ...
>
> NB: the FORMAT function doesn't exist on unix...
>
>
> Regards,
> Bernard Tremblay
>
>
>--
> \\\|///
> \\ - - //
> ( @ @ )
>+-----oOOo-(_)-oOOo-------+--------------------------------------+
>| Bernard Tremblay | |
>| La Capitale | Tel: (418) 646-2401 |
>| | Fax: (418) 646-5960 |
>| | Int: Bernard.Tremblay@capitale.qc.ca |
>+-------------------------+--------------------------------------+
>| Imaginasys enr | Res: (418) 658-1411 |
>| | Int: bertrem@quebectel.com |
>+--------------Oooo-------+--------------------------------------+
> oooO ( )
> ( ) ) /
> \ ( (_/
> \_)
>
>
>> Mark Bodt <markbodt@STSS.CO.NZ> writes
>> >At 11:57 6/07/99 -0400, you wrote:
>> >>Yo! SAS-L!
>> >>I need some help on checking for the existence of a specific format in the
>> >>WORK.FORMATS catalog.
>> >>The code below works; I wonder if there is an sql or scl solution which
>> >>might be faster.
>> >>
>> >>%LET HAVENVLD = 0;
>> >>/* enable this to return HAVE-INVALID=1 **
>> >>proc format; value $INVALID 'xyz'='1';
>> >>/*************************************/
>> >>data _NULL_;
>> >> do until(EndoFile);
>> >> set SASHELP.VCATALG(where=( LibName = 'WORK'
>> >> and MemName = 'FORMATS'
>> >> and MemType = 'CATALOG'
>> >> and ObjName = 'INVALID'
>> >> and ObjType = 'FORMATC'
>> >> ) )
>> >> end = EndoFile;
>> >> HaveNvld = '1'; end;
>> >> call symput('HAVENVLD',HaveNvld);
>> >>stop;run;%put HAVENVLD<&HAVENVLD.>;
>> >>*NOTE: The DATA statement used 2.29 seconds.;
>> >>
>> >>thanx
>> >>Ron Fehd the macro maven CDC Atlanta GA
>> >>
>> >
>> >I asked a similar question quite some time ago (21 Jan 1997).
>> >
>> >Darrell Edgley <Darrell_Edgley@SANDWICH.PFIZER.COM> suggested the following
>> >solution:
>> >
>> >IF FORMAT('$brkfmt.','C') THEN .... /* Format valid */ ;
>> >ELSE .... /* Format not valid */ ;
>> >
>> >HTH
>> >
>> >Mark
>> >
>> >
>> >
>> >
>> >+------------------------------------------+--------------------------+
>> >| Mark Bodt | |
>> >| Sunken Treasure Software Systems Ltd | SAS Institute(NZ) Ltd. |
>> >| Specialising in SAS(R) Software | Quality Partner. |
>> >| Consultancy in the Asia / Pacific Region | |
>> >+------------------------------------------+--------------------------+
>> >| PO Box 9472, Marion Square, Wellington, New Zealand |
>> >| Ph (025) 725 386 Fax +64 4 385 8670 Email: markbodt@stss.co.nz |
>> >+---------------------------------------------------------------------+
>>
>> Mark or Darrell's idea may not be represented quite correctly.
>>
>> Liking the idea enough to try it, I've pasted some log and debug session
>> and commented below
>> -==-=-=-=-=-=-=-=-=--==-=-=-=-=-=-=-=-=--==-=-=-=-=-=-=-=-=--=-=-=-=-
>> 14 DATA /DEBUG ;
>> 15
>> 16 IF PUTC( 'C', '$brkfmt.') THEN FOUND=1;
>> 17 ELSE FOUND=0;
>> 18 RUN;
>>
>> =-=-=-=-=-=-=-debug log with monitoring of _error_=-=-=-=-=-=-
>> Stepped to line 17 column 12
>> > E _ALL_
>> FOUND = .
>> _ERROR_ = 1
>> _N_ = 1
>> >
>> Stepped to line 18 column 1
>> > ?
>> Unrecognized command: ?
>> > E _ALL_
>> FOUND = 0
>> _ERROR_ = 1
>> _N_ = 1
>>
>> NOTE: Character values have been converted to numeric values at the
>> places given by: (Line):(Column).
>> 16:8
>> NOTE: Invalid second argument to function PUTC at line 16 column 8.
>>
>> I could find no FORMAT() function
>> The data step won't compile if an unknown format is found in a PUT()
>> But here PUTC() and presumably PUTN() only create run-time conditions -
>> I can trap _error_ after the putC() call
>>
>> 31 DATA ;
>> 32 retain testing '$brkfmt.' ;
>> 33
>> 34 IF PUTC( 'C', testing ) THEN FOUND=1;
>> 35 ELSE FOUND=0;
>> 36 if _error_ then do;
>> 37 put 'WARNING: format ' testing ' not found' ;
>> 38 _error_= 0;
>> 39 end;
>> 40 RUN;
>>
>> NOTE: Character values have been converted to numeric values at the
>> (Line):(Column).
>> 34:8
>> NOTE: Invalid second argument to function PUTC at line 34 column 8.
>> WARNING: format $brkfmt. not found
>>
>> Your solution in general, would need to support numeric and character
>> and informats as well ::= putn() / putc() / inputn() / inputc()
>>
>> Using the alternative cexist() to verify existence of a format catalog
>> entry will need too much fuss before v7/8 catalog concatenation becomes
>> available
>> --
>> Peter Crawford
>
>--
> \\\|///
> \\ - - //
> ( @ @ )
>+-----oOOo-(_)-oOOo-------+--------------------------------------+
>| Bernard Tremblay | |
>| La Capitale | Tel: (418) 646-2401 |
>| | Fax: (418) 646-5960 |
>| | Int: Bernard.Tremblay@capitale.qc.ca |
>+-------------------------+--------------------------------------+
>| Imaginasys enr | Res: (418) 658-1411 |
>| | Int: bertrem@quebectel.com |
>+--------------Oooo-------+--------------------------------------+
> oooO ( )
> ( ) ) /
> \ ( (_/
> \_)
--
Peter Crawford (_knowledge_ is a poor substitute for *real* experience,
but they make a great team)
|