BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8


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 

4 REPLIES 4
Patrick
Opal | Level 21

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.

brophymj
Quartz | Level 8

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

data_null__
Jade | Level 19

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.

data_null__
Jade | Level 19

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1677 views
  • 0 likes
  • 3 in conversation