BookmarkSubscribeRSS Feed
armor
Calcite | Level 5
it is a very simple problem: when I use the following code to import my tab delimited txt file, the last column (if it is number) will be treated as character. It is so strange, anyone met the same problem?

PROC IMPORT OUT= cpa.score
DATAFILE= "/home/sg/cc/cpa/score.txt"
DBMS=TAB REPLACE;

GETNAMES=YES;
GUESSINGROWS=10000;
DATAROW=2;
RUN;


My temporary solution is to manully add in a 'junk' column into my txt file as the last column, so my real last column become the second-last column, then the problem gone.
5 REPLIES 5
andreas_lds
Jade | Level 19
Just guessing: the text file has been created on a Windows PC and SAS is running on Unix/Linux. One difference between both operating systems is the newline char. While Windows uses Carriage Return and Line Feed, the *nix-systems use only one of the chars. The problem can be solved by using dos2unix in the shell of the unix-box to transform the newline chars.
armor
Calcite | Level 5
Just guessing: the text file has been created on a Windows PC and SAS is running on Unix/Linux.
====================================

andreas, you are right, I create the txt file on my desktop and then upload it to the EG server.

I will go back to test it next Monday, and then feedback my results/solution(s).

Thanks,
armor
Calcite | Level 5
I tried the simplest solution for me to do, and it works,

"
format os1 best32.;
os1=substr(os,1,length(os)-1)*1;
"

my old variable os is a char variable with a anoiyning Carriage Return or Line Feed (or whatever it is, but it is an invisible char at the tail of the variable in my SAS table). I used substr function to remove it and then times 1, then i got my new os1 in numeric format. Message was edited by: armor
prholland
Fluorite | Level 6
You could also try the following, which removes the specific extra character, if it is there, whether you're using Windows or Unix/Linux:

new_var = compress(old_var, '0D'x);

...........Phil
deleted_user
Not applicable
You can also use a data step solution :

data ... ;
attrib
... ;
infile
'your/file.txt' dlm = ... TERMSTR = CRLF ;
input
... ;
run ;

"TERMSTR = CRLF" will tell SAS that lines are ending with a Carriage Return / Line Feed (Windows format).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3564 views
  • 0 likes
  • 4 in conversation