Date: Thu, 27 May 2004 11:50:37 -0400
Reply-To: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject: Re: No macvar resolve inside inline data
The code works in the special case where macrovariables to be resolved
appear in only the first line of data. Try inserting another line
immediately after the CARDS statement, for example:
cards;
0
&ValList
and it will fail, as I anticipated in my earlier post.
On Thu, 27 May 2004 11:12:59 +0200, Groeneveld, Jim
<jim.groeneveld@VITATRON.COM> wrote:
>Hi friends,
>
>The following code appears to perform well as well:
>
>%LET ValList=1 2 3;
>
>DATA _NULL_;
> INPUT @;
> _INFILE_= RESOLVE(_INFILE_);
> INPUT Value @@;
> PUT Value=;
> CARDS;
>&ValList
>;
>RUN;
>
>The only wish is to get rid of the SAS note:
>"SAS went to a new line when INPUT statement reached past the end of a
line."
>which appears with the default FLOWOVER option on the INFILE statement
anyway
>if reading multiple records from a single line.
>The other options (TRUNCOVER MISSOVER STOPOVER) do not seem to work as
desired.
>
>Regards - Jim.
>--
>. . . . . . . . . . . . . . . .
>
>Jim Groeneveld, MSc.
>Biostatistician
>Science Team
>Vitatron B.V.
>Meander 1051
>6825 MJ Arnhem
>Tel: +31/0 26 376 7365
>Fax: +31/0 26 376 7305
>Jim.Groeneveld@Vitatron.com
>www.vitatron.com
>
>My computer may have missed me, I did not; it, that is.
>
>[common disclaimer]
>
>
>-----Original Message-----
>From: Howard Schreier [mailto:Howard_Schreier@ITA.DOC.GOV]
>Sent: Tuesday, May 25, 2004 21:58
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: No macvar resolve inside inline data
>
>
>One can also use an "empty" INPUT statement with a single trailing @:
>
> input @;
>
>then apply the RESOLVE function to the automatic variable _INFILE_
>
> _infile_ = resolve(_infile_);
>
>and finally use a second INPUT statement to scan the resolved string
>
> input [whatever];
>
>Jim's requirement is complicated though, because he wants to use a double
>trailing @. That's very hard to coordinate with the RESOLVE function
>because the function would need to be invoked whenever SAS rolls to a new
>line, and that event happens "inside" the INPUT statement.
>
>It can be done with two passes and an intermediate file. For example:
>
> %LET ValList=1 2 3;
>
> filename resolved tmp;
>
> data _null_;
> file resolved;
> input;
> _infile_ = resolve(_infile_);
> put _infile_;
> cards;
> 3 2
> &ValList
> 2 1
> ;
>
> data _null_;
> infile resolved;
> input Value @@ ;
> put (_n_ Value)(=);
> run;
>
>Results:
>
> _N_=1 Value=3
> _N_=2 Value=2
> _N_=3 Value=1
> _N_=4 Value=2
> _N_=5 Value=3
> _N_=6 Value=2
> _N_=7 Value=1
>
>On Tue, 25 May 2004 11:34:53 -0400, Ian Whitlock <iw1junk@EARTHLINK.NET>
>wrote:
>
>>Jim Groeneveld <jim.groeneveld@VITATRON.COM> asked:
>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>
>>Was it known to anyone of you that macro variable resolution does not take
>>place inside the values part of inline data (in a data step)? Example:
>>
>>%LET ValList=1 2 3;
>>DATA _NULL_;
>> INPUT Value @@;
>> PUT Value=;
>> CARDS;
>>&ValList
>>;
>>RUN;
>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>
>>Jim I wouldn't expect data to be sent to the macro facility to be
>>processed. The macro facility is for preproessing text into SAS code, not
>>data. I would think such a ting to be a highly suspect idea.
>>
>>However, SAS does provide the RESOLVE function for resolving a macro
>>expression held in a character string.
>>
>>%LET ValList=1 2 3;
>>DATA _NULL_;
>> INPUT Value $20.;
>> value = resolve ( value ) ;
>> PUT Value=;
>> CARDS;
>>&ValList
>>;
>>RUN;
>>
>>Result
>>Value=1 2 3
>>
>>
>>Ian Whitlock
>>iwhitlock@earthlink.net
|