BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
willy0625
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

7 REPLIES 7
Linlin
Lapis Lazuli | Level 10

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

art297
Opal | Level 21

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

willy0625
Calcite | Level 5

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..

art297
Opal | Level 21

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

willy0625
Calcite | Level 5


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

art297
Opal | Level 21

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.

art297
Opal | Level 21

: 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

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
  • 7 replies
  • 1065 views
  • 3 likes
  • 3 in conversation