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 (September 2000, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 14 Sep 2000 17:08:34 GMT
Reply-To:     sashole@mediaone.net
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: Returning VALUE from &datatyp Macro
Comments: To: dbrown@GPO.GOV
Content-Type: text/plain; format=flowed

Don,

Since it appears that the only reason you are trying to use the DATATYP is to establish whether a DATA step character variable NumberC is a digital string or contains an alpha character, using the macro function with the additional layer of CALL EXECUTE complexity seems to be a little bit excessive. The DATA step has ample means of doing it per se. For instance, consider this:

20 data _null_; 21 input NumberC: $4.; 22 if input('0000', pib4.) <= 23 input(NumberC,pib4.) <= 24 input('9999', pib4.) then put NumberC 'is number.'; 25 else put NumberC 'has alpha.'; 26 cards; 0000 is number. 000A has alpha. 0002 is number. 0003 is number. 0005 is number.

The above will work anywhere, however if you work on the real computer (and hence have EBCDIC), it can be simplified:

35 data _null_; 36 input NumberC: $4.; 37 if '0000' <= NumberC <= '9999' then put NumberC 'is number.'; 38 else put NumberC 'is alpha. '; 39 cards; 0000 is number. 000A is alpha. 0002 is number. 0003 is number. 0005 is number.

Finally (and perhaps simpler if not faster), the VERIFY function can do the job:

67 data _null_; 68 input NumberC: $4. @@; 69 if verify (numberc,'0123456789') then put NumberC 'is alpha. '; 70 else put NumberC 'is number.'; 71 cards; 0000 is number. 000A is alpha. 0002 is number. 0003 is number. 0005 is number.

Kind regards, ===================== Paul M. Dorfman Jacksonville, Fl =====================

>From: "Brown, Donald W. II" <dbrown@GPO.GOV> >Reply-To: "Brown, Donald W. II" <dbrown@GPO.GOV> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Returning VALUE from &datatyp Macro >Date: Thu, 14 Sep 2000 11:05:15 -0400 > >SAS enthusiasts, > >Is there a way to extract the result (value=CHAR/NUMERIC) of the &datatyp >macro into a variable that is available to the data step that is attempting >to execute the macro? For instance, following the call to the macro I would >code a statement like IF whatever = 'CHAR' THEN DELETE;. The test below >appears to show that at least it is evaluating the data as I expected but I >can't seem to find a way to get the values CHAR or NUMERIC into a variable >that I can reference. I've tried numerous variations and have gotten it to >generate a VARIABLE named CHAR but not a VALUE! > >Thanks in advance for any help/hints > >Don Brown >DBA (& apparent SAS non-programmer attempting to play one at work) >U.S.G.P.O. > >508 %macro NumTest; >509 %if %datatyp(&Number)=NUMERIC %then %do; >510 %put The MemberName "&number" is NUMERIC.; >511 %end; >512 %else %do; >513 %put Error: The MemberName "&number" contains CHARs.; >514 %end; >515 %mend NumTest; >516 >517 *FILENAME PDSDIR 'D:/TEMP/PDSDIR.TXT'; >518 *FILENAME CONTROLS 'D:/TEMP/CONTROLS.TXT'; >519 /* Step 1: Read, test & keep the #nnnn member names */ >520 Data Dir; >521 Infile Cards; >522 Input @1 Tag $Char1. @; >523 If Tag = '#'; >524 Input @2 NumberC $Char4.; >525 Call symput("Number",NumberC); >526 Call execute('%numtest'); >527 Cards; > >The MemberName "0000" is NUMERIC. >Error: The MemberName "000A" contains CHARs. >The MemberName "0002" is NUMERIC. >The MemberName "0003" is NUMERIC. >The MemberName "0005" is NUMERIC. >NOTE: The data set WORK.DIR has 5 observations and 2 variables. >NOTE: DATA statement used: > real time 0.11 seconds > >533 Run; > >NOTE: CALL EXECUTE routine executed successfully, but no SAS statements >were >generated.

_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at http://profiles.msn.com.


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