LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 1999, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 9 Mar 1999 16:51:28 +0100
Reply-To:     Frank Poppe <Frank.Poppe@SWOV.NL>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Frank Poppe <Frank.Poppe@SWOV.NL>
Organization: SWOV
Subject:      Re: Help with character to numeric conversion.
Comments: To: Stephen Dybas <skd02@HEALTH.STATE.NY.US>
Content-type: text/plain; charset=us-ascii

Hi,

If the only task is to have an ASCII file OUTFILE with the number of records treated in Z6.0 format, just do it in the first datastep:

if last then do ; file outfile ; put _N_ z6.0 ; end;

If, for some reason, you (also) want to have the value in a macro variable you could use

if last then do ; call symput ( 'lstrec' , _N_ ) ; end ;

This will give a warning, saying that numeric values have been converted to character. This is the value _N_, converted to the macro character string. You probably have been trying to do this explicitly, but using the wrong function: lastrec = input(_n_, $char6.);

I am not entirely sure what will happen, but it seems that while _N_ <1e6 LASTREC will be empty, and above that only the leftmost characters.

If you had inserted a %put &lstrec ; statement between steps you would have seen the actual value.

If you have the right value in the macro variable, easy ways to use it in a datastep are assigning it a value:

chrcount = &lstrec ;

or initializing it:

retain chrcount &lstrec ;

I hope this clarifies the use of macro variables a bit.

-- Frank Poppe /--- | Stichting Wetenschappelijk Onderzoek Verkeersveiligheid SWOV | SWOV Institute for Road Safety Research | | PO Box 1090 telephone: + 31 70 3209323 | 2260 BB Leidschendam fax: + 31 70 3201261 | the Netherlands e-mail: <Frank.Poppe@SWOV.nl> \-----------------------

Stephen Dybas schreef:

> To SAS-L: > > I hope someone can help. > > I need to be able to print the number of records I am transmitting on a > trailer record. > > I've tried a number of different ways to get the macro variable 'lstrec' > converted to a nummeric > that can be formatted with the zw. format but it always seems to come up > missing. > > Here is the stripped down code... > > data lastrecd; > set datafile end=last; /* Assume datafile is not empty */ > > if last then do; > lastrec = input(_n_, $char6.); > call symput('lstrec', lastrec); > end; > > run; > > data trailer; > chrcount = symget('lstrec'); > numcount = ??? /* Need to convert character variable 'chrcount' */ > /* to a numeric variable 'numcount' /* > run; > > data _null_; > file outfile; > set trailer; > put @1 numcount z6.; /* So that I can put the numeric value to an */ > /* output file in zw. format */ > run; > > Thanks in advance for your help.


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