01-26-2015 05:37 PM
Is there a way to change a csv file to read in as ASCII? I have been having problems all day evaluating text strings and it turns out the problem was the csv file. When I convert it to ASCII all the logic worked. So I wanted to know if the csv file can be converted in the infile data step so it reads in correctly.
01-26-2015 06:12 PM
If you read the CSV file with a data step you may be able to address this with an Encoding='encoding value' option on the infile or as a dataset option.
But without more specific information we're kind of shooting in the dark.
01-27-2015 07:38 AM
More detail: I am importing data from a csv file stored on a unix server. I read the data in with an infile statement. There are 3 variables, location$6. infono$12. and listname $50. The file appears to import correctly but when I use my error logic to compare the listname variable which contains variable length character values to a hard coded list I have in my program using a %LET todaylist = ('list1_file','list2_file','file_another'); all fail the compare. I ftp'ed the csv to my desktop and then back up to unix and using a transfer protocal of ascii. Read in that csv file then the compares worked. So SAS is not actually "seeing" the values in the listname field in the csv file. How do I get SAS to read the file correctly so this does not happen? I am writing an automated report and cannot download/upload the file daily. I have to use the csv copy provided on the server.
01-27-2015 07:59 AM
The only change that could have happened by using FTP to move a file to and from DOS using ASCII setting is that the extra Carriage Return character that DOS uses to mark the end of line would be removed. Since the variable LISTNAME is the last one on the line it is possible your original program was reading the CR as part of the data.
Here are some ways to modify your INFILE statement to handle that.
1) If you know for sure that you file is using CR+LF as the end of line markers then add TERMSTR=CRLF option to your INFILE statement.
2) You can change your delimiters from just comma to comma or CR.
3) You can compress the CR character out of the variable LISTNAME.
data want ;
infile 'myfile.csv' dsd firstobs=2 termstr=crlf truncover ;
length location $6 infono $12 listname $50 ;
input location infono listname ;
01-27-2015 11:21 AM
Open the files on Unix with a simple editor (vi). If you see ^M at the end of each line, you have the DOS CRLFs there. Use the TERMSTRING option or make sure that the CR characters are removed during filetransfer.