- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-02-2009 10:59 PM
(3916 views)
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
====================================
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
"
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
new_var = compress(old_var, '0D'x);
...........Phil
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
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).