Help using Base SAS procedures

importing a text file

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

importing a text file

Hi SAS users.

I am trying to import the attached text file.

This is what I've written in an attempt to read in the text file:

data test;

infile 'location-of-the-file/test.txt';

input month RM $ Initials $ plan ;

run;

For some reason the plan column is not being read properly. The plan column is supposed to be integer valued.

Could someone advise me what I am doing wrong?

Attachment

Accepted Solutions
Solution
‎01-10-2013 09:35 PM
PROC Star
Posts: 7,492

Re: importing a text file

Posted in reply to willy0625

I've never used Linux, thus I'm kind of at a loss to be able to suggest what you might do.

Unlike the file you posted, all of your numbers for the last field appear to end with a letter M.

The only thing I can suggest is to use a input statement (with no variables identified), use the tranwrd function to replace

"M 2" with " 2", and then grab the 4 fields from _infile_

Hopefully, someone who has worked with Linux can assist you better than I can.

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: importing a text file

Posted in reply to willy0625

Hi,

I ran your code. No problem for me:

data test;

  infile 'C:\temp\forum\test.txt';

  input  month RM $ Initials $ plan ;

  run;

  proc print;run;

                       Obs    month      RM      Initials      plan

                    1      2013    Kenny      KJG        1227466

                    2      2013    Sarah      SYY         810013

                    3      2013    Ryan       RSK         994884

                    4      2013    Vinday     VXC         855295

                    5      2013    Marie      MXM        1412827

                    6      2013    George     GWL        1119429

                    7      2013    Chris      CXD        1205086

                    8      2013    Total      (ALL)      7625000

PROC Star
Posts: 7,492

Re: importing a text file

Posted in reply to willy0625

Appears to read in perfectly, for me, using your code.  What kind of result are you getting?

Contributor
Posts: 27

Re: importing a text file

Hi all.

Thanks for your replies.

This is what I get:

month RM Initials plan

2013 Kenny KJG .

2013 Sarah SYY .

2013 Ryan RSK .

2013 Vinday VXC .

2013 Marie MXM .

2013 George GWL .

2013 Chris CXD .

2013 Total (ALL) 7625000

Hmm this is weird..

PROC Star
Posts: 7,492

Re: importing a text file

Posted in reply to willy0625

What kind of system are you on?  Which version of SAS are you using?  Can you post the actual code that you ran?

Contributor
Posts: 27

Re: importing a text file


I am using SAS EG 4.1(4.1.0.1020) - a bit old school?

under Windows XP

%put &sysscp

returns LINUX.

I've attached the log I get.

Thanks

Attachment
Solution
‎01-10-2013 09:35 PM
PROC Star
Posts: 7,492

Re: importing a text file

Posted in reply to willy0625

I've never used Linux, thus I'm kind of at a loss to be able to suggest what you might do.

Unlike the file you posted, all of your numbers for the last field appear to end with a letter M.

The only thing I can suggest is to use a input statement (with no variables identified), use the tranwrd function to replace

"M 2" with " 2", and then grab the 4 fields from _infile_

Hopefully, someone who has worked with Linux can assist you better than I can.

PROC Star
Posts: 7,492

Re: importing a text file

Posted in reply to willy0625

: On the other hand, your system may be expecting only a CR or a CR and LF combination.

I would try your original code with an extra option specified in the infile statement.  I'm not sure which you will need.  Try:

termstr=CRLF

and, if that doesn't work, try:

termstr=LF

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 221 views
  • 3 likes
  • 3 in conversation