- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a text file I am trying to read into sas but I can't get it to read in properly. The problem is that loads of the rows have blank fields so when I read in using this code, the code skips over the blanks and all the values are squeezed into the first few columns. The structure of the txt file is such that each column is separated by a blank. so the first few columns of the first rows looks like:
Key............ .......Quote No Cover
5543 5,543
6,655
You will see that the second row in the above example has nothing under Key. I want the data to be read in so that it leaves a cell blank if there is nothing there.
Here is the code I'm using:
data FLEET;
infile FLEET dsd lrecl = 10000 firstobs=2;
format
key $15.
quote_no $15.
fleet_type $1.
exp_veh_type $20.
exp_sr $17.
exp_comp_vehs $15.
exp_tpft_vehs $15.
exp_tp_vehs $15.
exp_prpv $17.
trailers_tsi $15.
trailers_rate $16.
adft_tsi $15.
;
input
key
quote_no
fleet_type
exp_veh_type
exp_sr
exp_comp_vehs
exp_tpft_vehs
exp_tp_vehs
exp_prpv
trailers_tsi
trailers_rate
adft_tsi
;
run;
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are different input styles depending on how your source data file looks like. You write that "each column is separated by a blank" but then the data you're posting looks like the data is on certain positions.
The issue with "each column is separated by a blank" is "missing values". So in such a case would we have 3 consecutive blanks? Or what would tell us that a sequence of blanks actually isn't just a delimiter for a column. On the other hand if your data is "positional" (as it looks like in the data you've posted) then reading this data would be quite simple.
I suggest you attach a text file with a few rows of your data. That would make it much easier for us to give you some advice of how to read this data into SAS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have attached the actual text file with the first 20 rows.
Also, is there a simple way of duplicating the key until it reaches the next values so
key
5564
5566
becomes
5564
5564
5564
...
...
5566
5566
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Column input or formatted input with column pointers.
You need to look at the documentation for the INPUT statement.
If you have a new question start a new thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the fields are blank delimited the DSD option is wrong, not needed.
If the fields are blank delimited and the missing values are not marked (also blank) then you cannot use LIST input.
You might be able to use column input.
You might have delimiter that cannot see like a tab.
You need to provide complete information about what you have.