Date: Sat, 22 Jun 1996 17:43:44 EDT
Reply-To: markbodt@stss.co.nz
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Mark Bodt <markbodt@STSS.CO.NZ>
Subject: Re: delimiters
>My colleague has a file which has "," delimiters between all but two
>columns. How does one write an input statement for this file
>
>The datafile looks like:
>
>name , var1 , var2 , var3 var4 , var5
>
>(There is no comma between var3 and var4)
>
>Please email
>
>kevinchu@umich.edu
This msg sent to SAS-L & original poster.
Hi Kevin? It's a stormy late Saturday afternoon in the land of
eruptions and thought I'd try and solve your problem for fun.
You didn't specify whether Var1-5 were $ or numeric , so I assumed
numeric. The following code works, but you may need to fine tune it to
meet your requirements (lengths & var types etc). Also there are
probably several other ways to solve this one, so it will be intersting
to see what other replies are posted to SAS-L.
/*generate some test data & write it to
the file c:\temp\test.txt */
data _null_;
file 'c:\temp\test.txt';
input testdata $1-40;
put testdata;
cards;
Sally , 1 , 56 , 78 90 , 12
Bert , 5 , 23 , 12 34 , 33
Jim , 22 , 12 , 45 23 , 12
Herman , 22 , 4 , 11 44 , 2
;
*read in the test data from the file;
data test;
infile 'c:\temp\test.txt' dsd;
length name $30 temp $30;
/* The data for var3 & var4 is read in as a
character string called temp.
the scan function scans the temp var and
extracts the first 'word' for var3 and the
second 'word' for var4. The extracted 'words'
are converted to numeric vars with the put
function. */
input name var1 var2 temp var5;
var3=put(scan(temp,1,' '),8.);
var4=put(scan(temp,2,' '),8.);
*print converted data;
proc print;
var name var1-var5;
run;
Regards,
Mark
--
+--------------------------------------+--------------------------------+
| Mark Bodt | Specialising in |
| Sunken Treasure Software Systems Ltd | SAS Software Consultancy |
| 73 Pine Street | in the Asia / Pacific Region |
| Mt Eden, Auckland 4, New Zealand | |
| Ph (+64) 25 725 386 (cell phone) | |
| Fax +64 9 620 9079 | SAS Institute(NZ) Ltd. |
| | Quality Partner. |
| Email: markbodt@stss.co.nz | |
+--------------------------------------+--------------------------------+
|