Date: Fri, 10 Mar 2000 12:41:47 +0100
Reply-To: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Subject: Re: text file -> SAS data set
Content-Type: text/plain; charset="iso-8859-1"
Regarding your first issue, I would ask whether it is possible (and possibly
more easy) to force your CN program to deliver the desired values more
suitedly. If that is not possible I would read and analyse your file
approximately in the following *untested* way:
1. read a line (a line as in your message) into the variable FullLine (after
defining your INFILE)
INPUT FullLine $;
2. if it starts with IF the remainder is the variable Cond
IF UPCASE(SUBSTR(FullLine,1,2)) EQ "IF" THEN
3. if it starts with ELSE, ignore, don't process further
ELSE IF UPCASE(SUBSTR(FullLine,1,4)) EQ "ELSE" THEN ;
4. if it starts with THEN the remainder up to the [ is the variable Conclu
ELSE IF UPCASE(SUBSTR(FullLine,1,4)) EQ "THEN" THEN
Bracket = INDEX(FullLine,'['); * assumed always to be
Conclu = SUBSTR(FullLine, 5,Bracket-5);
from the [ up to the end it is the variable Size
Size = SUBSTR(FullLine,Bracket);
OUTPUT; * force an observation written after
5. in any other case it is an additional part of the Cond
Assuming I did interprete your file correctly and this is the actual layout.
Process starting, embedded and trailing spaces within the lines and
variables according to your own desire.
To answer your additional question in attempt 1: yes it it possible to
define more than one delimiter at the same time, but shouldn't you include a
space as well?
To answer your additional question in attempt 2: an INPUT statement like
<input @"IF" cond @"THEN" conclu @"["> is legal (and I do see how you would
like to have it work), but as you don't know which literal character string
to expect at any moment this method is not useful, but you should follow
some way like outlined above, reading and analysing complete lines.
Your suggestion to read a complete text file into a macro variable IMHO will
not work, as the %INCLUDE statement is not a macro statement at all
(resolving to the contents of the file); it is an exception.
A way to read a complete textfile into a single macro variable (FullFile) is
*untested, but the method has been applied in some other situation*:
%LET FullFile = ; * Define empty macro variable at this level;
LENGTH FullLine $ 80; * or longer;
INPUT FullLine $;
CALL EXECUTE ( '%ValueLst(FullFile,' || FullLine || ');' );
where ValueLst is the following *tested*, preceding macro:
%* Auxiliary ValueLst concatenates values into list ;
%MACRO ValueLst(ListVar,Value,ForMyUse) / DES='Make value list from values'
%IF ( %UPCASE(&ForMyUse) = COMPILE ) %THEN %GOTO Finish;
%LET &ListVar = &&&ListVar &Value; %* &ListVar already exist in calling
Ignore or remove the parts refering ForMyUse; I use those for compilation
and other author-only purposes. After the data step your whole text file is
available in the macro variable FullFile, to be used subsequently. You might
use this method to deduce the contents of your variables alternatively (not
Regards - Jim.
Y. (Jim) Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070
senior statistician, P.O. Box 1 fax. +31 412 407 080
head IT department 5350 AA BERGHEM IMRO TRAMARKO: a CRO
J.Groeneveld@ITGroups.com the Netherlands in clinical research
My computer seems more ≤įįį-compatible than I am myself.
> -----Original Message-----
> From: HALIMI RaphaŽl [SMTP:Raphael.HALIMI@GEP.FR]
> Sent: Friday, March 10, 2000 11:18 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: text file -> SAS data set
> Dear SAS-lers,
> This the new episode of "SAS & CN algorithm" (CN is a rule-induction
> Here is the CN output, in a text file :
> IF X4 = "1"
> THEN Y = "0" [49795 0]
> IF X3 = "3"
> THEN Y = "0" [12604 0]
> IF X5 > 4.50
> AND X6 > 2.50
> THEN Y = "0" [390 0]
> IF X1 > 64.96
> THEN Y = "1" [0 557]
> What I'd like to do is to transform this text file in a data set :
> COND conclu size
> X4 = "1" Y = "0" [49795 0]
> X3 = "3" Y= "0" [12604 0]
> X5 > 4.50 AND X6 > 2.50 Y = "0" [390 0]
> X1 > 64.96 Y= "1" [0 557]
> What I try (and fail) to do was :
> 1- working with several delimiters with an INFILE statement : impossible ?
> 2- working with an INPUT statement : input @"IF" cond @"THEN" conclu @"["
> Any help would be welcome,
> Thanks everyone !
> PS : is there an easy way to assign a macro-variable a whole text file
> (something like : %LET read= %STR(%include "path/text.txt";); ???)