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 (February 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 5 Feb 2003 16:33:51 -0600
Reply-To:     Kevin Myers <KevinMyers@AUSTIN.RR.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Kevin Myers <KevinMyers@AUSTIN.RR.COM>
Subject:      Re: Antwort: Re: comma delimited field parsing
Content-Type: text/plain; charset="iso-8859-1"

Thanks for the great tip Peter! Even after 20+ years of writing SAS code, it seems that I still learn new tricks very day.

s/KAM

----- Original Message ----- From: "Peter Crawford" <peter.crawford@db.com> To: "Kevin Myers" <KevinMyers@AUSTIN.RR.COM> Sent: Wednesday, February 05, 2003 4:20 PM Subject: Antwort: Re: comma delimited field parsing

in v8 you can write into _infile_ That is as simple as it gets...

Of course, you only get "one of those" in a datastep

To impose the dsd rules, you need an infile statement, but that _almost_ can point at dummy

Here is a trial ...... 245 data test1; 246 input var1 : $15. ; 247 put _all_; 248 cards;

var1=a,b,c,d,e,f _ERROR_=0 _N_=1 var1=,,,,, _ERROR_=0 _N_=2 var1=,,c,d,e,f _ERROR_=0 _N_=3 var1=a,b,,,e,f _ERROR_=0 _N_=4 NOTE: The data set WORK.TEST1 has 4 observations and 1 variables. NOTE: DATA statement used: real time 0.03 seconds cpu time 0.01 seconds

253 ; 254 data _null_; * ensure a dummy demo file is available; 255 file '!temp/demo'; put 'demo'; stop; 256 run;

NOTE: The file '!temp/demo' is: File Name=C:\TEMP\demo, RECFM=V,LRECL=256

NOTE: 1 record was written to the file '!temp/demo'. The minimum record length was 4. The maximum record length was 4. NOTE: DATA statement used: real time 0.01 seconds cpu time 0.00 seconds

257 data test2; 258 set test1; 259 * ensure an infile buffer is available; 260 infile '!temp/demo' dsd dlm=',' truncover lrecl=32000; 261 input @1 @@; 262 _infile_=var1; * load var1 ready for "input" parsing; 263 *define the vars to parse out of var1 ; 264 length a b c d e f $20; 265 input a b c d e f @@; **use @@ to keep that buffer; 266 put ( a--f )(=) @30 var1= ; 267 run;

NOTE: The infile '!temp/demo' is: File Name=C:\TEMP\demo, RECFM=V,LRECL=32000

a=a b=b c=c d=d e=e f=f var1=a,b,c,d,e,f a= b= c= d= e= f= var1=,,,,, a= b= c=c d=d e=e f=f var1=,,c,d,e,f a=a b=b c= d= e=e f=f var1=a,b,,,e,f NOTE: 1 record was read from the infile '!temp/demo'.

So it works !

Sorry you're not making it to sugi !!

Regards Peter Crawford

Datum: 05/02/2003 23:13 An: SAS-L@LISTSERV.UGA.EDU

Antwort an: Kevin Myers <KevinMyers@AUSTIN.RR.COM>

Betreff: Re: comma delimited field parsing Nachrichtentext:

Hi Peter -

Using dsd works great as long as you are reading values directly from a file, but not if you already have them in a variable. But maybe I am missing something...? You say "Just load _infile_ with var1, ...". I don't know how to accomplish that other than reading var1 directly from a dsd file. Do you have some other trick up your sleeve to get the value of var1 into _infile_? I'm guessing that you must, but I can't imagine what it might be offhand...

Sure do wish that I could make SUGI, but unfortunately I can't afford to make the trip. I've always wanted to go, but was never able to make the trip, even while I was with SAS. :-(

s/KAM

----- Original Message ----- From: "Peter Crawford" <peter.crawford@db.com> To: "Kevin Myers" <KevinMyers@AUSTIN.RR.COM> Cc: <SAS-L@LISTSERV.UGA.EDU> Sent: Wednesday, February 05, 2003 3:47 PM Subject: Re: comma delimited field parsing

Hi Kevin

I think the easy way to do this kind of thing is using the strength of dsd (theme of my sugi coders corner paper "More _Infile_ Magic" )

Just load _infile_ with var1, and then easily "input" those columns It only needs preceeding with a dsd based infile. Any quoted values are fully respected in dsd rules.

Hope you'll be able to come along to SUGI

Regards Peter Carwford

Datum: 05/02/2003 22:41 An: SAS-L@LISTSERV.UGA.EDU

Antwort an: Kevin Myers <KevinMyers@AUSTIN.RR.COM>

Betreff: Re: comma delimited field parsing Nachrichtentext:

If you can insure that your original strings won't include quoted values with imbedded commas, then you can go with Michael's approach of using tranwrd to pre-process the string before passing it into scan(). However, in the more general case that won't work because it will alter any values within quotes that include embedded commas.

s/KAM

----- Original Message ----- From: "Charles Patridge" <Charles_S_Patridge@PRODIGY.NET> Newsgroups: bit.listserv.sas-l To: <SAS-L@LISTSERV.UGA.EDU> Sent: Wednesday, February 05, 2003 2:47 PM Subject: Re: comma delimited field parsing

> Michelle, > > In the documentation of SAS, here is what I found: > > /*** SCAN FUNCTION: > SAS Language - Version 6 - Chapter 11 - Page 595 > Leading Delimiters before the first word have no effect. If there are > two or more contiguous delimiters, SCAN treats them as one. > ***/ > > > I'll see what I can do to get what you would like. > Regards, > Charles Patridge > > If you were reading in VAR1 = "a,b,c,d,e,f" from an external file, then > I would have suggested using the DSD option of the INFILE statement which > should have worked even if you had such strings as ",,c,,e,f". > > but dealing with a SAS variable already in that form requires a different > solution.

--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


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