- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
i have a small doubt. There is one txt file.
To import it into sas i used proc import method.
proc import datafile="D:\sample.txt"
out=ds
dbms=dlm
replace;
delimiter='09'X;
run;
By using this method some of the variables length is missing.
Suppose between variables here i mention i mention two variables. i.e. company name and sub branch company name.
Both are character variables.
sub branch length is 40 and it reads it completely.
But company name variable length is missing. its taking only 10.of
I don't know why its taken like that.
Is there any method to while reading the data from txt file to mention the length of variable. Is this possible in Proc Import.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why are you using PROC IMPORT?
If you know the data then just write a data step to read the file.
Are you sure the file is tab delimited? Is it possible it is just a text file and the text editor has inserted random tabs where it thinks it can save space by replacing multiple spaces with a tab?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As far as I am aware there is no method in proc import to set lengths. The reason is that proc import is a wrapper. Behind the scenes it is guessing what your data is and generating a datastep import program. This import program is normally written to the log for text files, so you can take that code that is generated and modify it as you want. IMO its not a good idea to use proc import as it "guesses" what its to do. You know the data so are best placed to tell the code what to do.
There may also be a couple of other things you want to be sure of, is the delimiter really 09X? Does the strings contain special characters etc. I would recommend a CSV format file with quoted strings to be safer, or if you want to go the whole hog, then XML. Are you saving from Excel perhaps? If so then you can just save as CSV from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Would adding the GUESSING rows option/statement fix your problem. Have you looked at the documentation for PROC IMPORT?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
GUESSING ROWS is worked in excel. here the data is tab delimited data. if the two variables having large size then some of the variables length is missing
so using proc import it is possible to mention length of variables while importing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to RTM.
The GUESSINGROWS statement is valid only for delimited files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try using CSV as dbms. If this doesn't work , i think you need to check the data and why its getting truncated.
proc import datafile="D:\sample.txt"
out=ds
dbms=csv
replace;
delimiter='09'X;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
i used your method vish33 Sir but same result i am getting. Although there is no changes in data using dbms=tab or dbms=csv.
variables length is missing. all are character variables.
Is there any efficient method that while importing mention variables size.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why are you using PROC IMPORT?
If you know the data then just write a data step to read the file.
Are you sure the file is tab delimited? Is it possible it is just a text file and the text editor has inserted random tabs where it thinks it can save space by replacing multiple spaces with a tab?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank u for your valid comments. I follow data step infile statement to read the full length of variable. I used colon":" before of every variable. Ex: company_name: $50.
So i got the result. Once again thank u all for spending time for my post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Delimiter option is not valid for DBMS=CSV, for obvious reasons.
'09'X is TAB. Try that as DBMS.
If that is not working for you, consider to use the data step instead, were you have complete control of field length etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is not an import but it reads txt files. My normal record is 77 bytes long; Jim
data master;
infile '/folders/myfolders/rawfiles/pre44.txt'
obs=99 length=rli dlm=’09’x;
input dat: $varying200. rli @ ;
x=rli; put _all_;
IF X = 77 THEN DO;
input @5 cat $10. @15 desc $30. @47 yr $10.
@54 c7 $8. @64 c8 $8. @70 c10 $8.;
END;
run;
proc print;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
When reading delimited files formatted input is not appropriate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Perhaps attach the sample.txt file (or a smaller version of it if it is large), so that we can see the data you're trying to read and show us what output you're seeing.
When you say "But company name variable length is missing. its taking only 10.of" Do you mean only the first 10 characters of company name are being read or only 10 fields are being read, or something else?
Regards,
Amir.