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>
Subject: Re: Help with character to numeric conversion.
Content-type: text/plain; charset=us-ascii
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 ;
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_ ) ;
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.
| 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
> 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);
> data trailer;
> chrcount = symget('lstrec');
> numcount = ??? /* Need to convert character variable 'chrcount' */
> /* to a numeric variable 'numcount' /*
> 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 */
> Thanks in advance for your help.