Desktop productivity for business analysts and programmers

SAS EG Proc Import always treats my last column as character

Reply
Occasional Contributor
Posts: 14

SAS EG Proc Import always treats my last column as character

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.
Regular Contributor
Posts: 235

Re: SAS EG Proc Import always treats my last column as character

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.
Occasional Contributor
Posts: 14

Re: SAS EG Proc Import always treats my last column as character

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,
Occasional Contributor
Posts: 14

Re: SAS EG Proc Import always treats my last column as character

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
Frequent Contributor
Posts: 81

Re: SAS EG Proc Import always treats my last column as character

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
N/A
Posts: 0

Re: SAS EG Proc Import always treats my last column as character

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).
Ask a Question
Discussion stats
  • 5 replies
  • 1618 views
  • 0 likes
  • 4 in conversation