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 (March 2000, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Mar 2000 14:43:08 +0100
Reply-To:     HALIMI Raphaël <Raphael.HALIMI@GEP.FR>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         HALIMI Raphaël <Raphael.HALIMI@GEP.FR>
Subject:      Re: text file -> SAS data set
Comments: To: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Content-Type: text/plain; charset="iso-8859-1"

Jim,

I always enjoy reading your solutions. At each times, I learn something !

By the way, I've tried this solution :

data read; infile myfile; input FullLine $; run;

And the results : OBS READ -------------- 1 IF 2 THEN 3 ELSE 4 IF 5 THEN . ELSE . . . . . .

So I tried :

data read; infile myfile delimiter="]"; input FullLine $; run;

And the results : OBS READ ----------------- 1 IF X4 = "1" 2 THEN Y = "0" [49795 0 3 ELSE 4 IF X3 = "3" 5 THEN Y = "0" [12604 0 6 ELSE 7 IF X3 = "1" 8 THEN Y = "0" [12474 0 9 ELSE . . . . . .

---> That's why I was looking for several delimiters (that is : IF, THEN, and ELSE). Now, I can't understand why the 2nd of my programs isn't correct !? I thought I will have this kind of data : OBS READ ----------------- 1 IF X4 = "1" THEN Y = "0" [49795 0 2 ELSE IF X3 = "3" THEN Y = "0" [12604 0 3 ELSE IF X3 = "1" THEN Y = "0" [12474 0 ..........

Do I make an obvious mistake ?

> ---------- > De : Jim Groeneveld[SMTP:J.Groeneveld@ITGROUPS.COM] > Répondre à : Jim Groeneveld > Date : vendredi 10 mars 2000 12:41 > A : SAS-L@LISTSERV.UGA.EDU > Objet : Re: text file -> SAS data set > > Raphaël, > > 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 > Cond=SUBSTR(FullLine,3); > 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 > DO; > Bracket = INDEX(FullLine,'['); * assumed always to be > positively found; > 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 > found Size; > END; > 5. in any other case it is an additional part of the Cond > ELSE Cond=Cond||FullLine; > 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; > DATA dataset; > INFILE <specification(s)>; > LENGTH FullLine $ 80; * or longer; > INPUT FullLine $; > CALL EXECUTE ( '%ValueLst(FullFile,' || FullLine || ');' ); > RUN; > > 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' > /*STORE*/; > %IF ( %UPCASE(&ForMyUse) = COMPILE ) %THEN %GOTO Finish; > %LET &ListVar = &&&ListVar &Value; %* &ListVar already exist in calling > macro; > %Finish: > %MEND ValueLst; > > 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 > suggested here). > > 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 > > algorithm). > > Here is the CN output, in a text file : > > > > IF X4 = "1" > > THEN Y = "0" [49795 0] > > ELSE > > IF X3 = "3" > > THEN Y = "0" [12604 0] > > ELSE > > IF X5 > 4.50 > > AND X6 > 2.50 > > THEN Y = "0" [390 0] > > ELSE > > 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 > ? > > (delimiter="IFTHEN[") > > 2- working with an INPUT statement : input @"IF" cond @"THEN" conclu > @"[" > > size; > > > > 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";); ???) > > > > Raphael >


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