Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INFILE Query 1

Status
Not open for further replies.

smalek

Programmer
Jan 15, 2009
28
CA
Hi
I have a raw file with the following layout
"GERI"|""|"09/03/09"|"MA3"|"09/03/09"|""|""|""|""|"19/03/09"

I woulid like to import the data directly into a data set by using infile. I wrote the following code but was unsuccessfull. data raw;
infile 'test' DLM='|' DSD MISSOVER;
input var1 $4 var2 $4 var3 ddmmyy10. var4 $3 var5 ddmmyy10.
var6-var10 ddmmyy10.;
run;
In the output I keep getting the fields in the worng columns and some actually get imported with the delimiter and the quotation.
"GER |"09/03 MA3 . . . . . . . . . |"19/03

Any suggestions?
Thanks


 
The problem here is that you're telling SAS exactly what to read in in your input statement.
There is probably a way to do what you're doing correctly, but I've never been able to work it out. I always use this method:-
Code:
data raw;
  infile 'test' DLM='|' DSD MISSOVER;
  length var1 $4
         var2 $4
         var3 6
         var4 $3
         var5 6
         var6-var10 6;

  informat var3 var5 var6-var10 ddmmyy10.;
  format var3 var5 var6-var10 ddmmyy10.;

  input var1-var10
        ;
run;
It's a slightly longer way of specifying it, however it allows SAS to determine what to read in, and it's never failed me.
Actually that's a lie, it failed me earlier this week for the first time ever, this for some reason doesn't work when reading in a fixed length record where you specify the physical position of the data item in the file, so I had to read in my date fields as text, then use the input function to convert it.
But under all other situations, the above has worked perfectly and been pretty bullet proof.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
You are definitely right. It is bullet proof and it worked absolutely smoothly without any hiccups.
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top