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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 2752 views
  • 0 likes
  • 4 in conversation