0
votes

I have a datafile which uses blank space as delimiter. I want to write a data step to read this file into sas.

The fields are not separated by a single blanks in most of the cases the fields are separated by more than 10 blanks spaces.I have checked using notepad++ and the delimiters are not tabs.

137          3.35          Afghanistan                      2009-07-08 
154          2.43          Albania                          2009-07-22
101          1.22          Antigua and Barbuda              2009-06-24 
155          4.13          Federated States of Micronesia   2009-07-22

I am tried writing informat statements for these and have been unsuccessful

Here's what I have done so far

input casedt1id :$3. contntid :4 country :&$32. casedt1 yymmdd10.

This reads only the first field properly and the rest get missing values.

The question is to write an informat statement to read this data ?

thanks for the help.

regards jana

2
Is the data really in fixed columns like your example? Did you try just telling SAS which columns to read for each variable?Tom

2 Answers

2
votes

You can use the @ symbol to control where the pointer reads from on the line. It looks like you have a fixed starting column for each variable.

data want;
input @1 casedt1id :$3. @14 contntid :4 @28 country :&$32. @61 casedt1 :yymmdd10.;
format casedt1 yymmdd10.;
datalines;
137          3.35          Afghanistan                      2009-07-08 
154          2.43          Albania                          2009-07-22
101          1.22          Antigua and Barbuda              2009-06-24 
155          4.13          Federated States of Micronesia   2009-07-22
;
0
votes

That looks like fixed column data to me. The problem then is using INFORMATs with fixed column data. This should work

input casedt1id $ 1-3 contntid 4-27 country $28-60 casedt1 yymmdd10.;
format casedt1 yymmdd10.;

The trick is make sure the pointer is in the right place when it tries to read the formatted text. So in the statement above that is done by telling it read to column 60 for COUNTRY. So now you are at column 61 when you are ready to read the date. You could also use + or @ to move the pointer.

... @61 casedt1 yymmdd10. ...

If you are reading from a variable length file (most files now are variable length) then make sure to add the TRUNCOVER option to the INFILE statement just in case the date is missing or written using fewer than 10 characters.