BookmarkSubscribeRSS Feed
angelinading
Fluorite | Level 6

Hi all,

 

So I have a .csv file and TITER values are sometimes a ratio and sometimes a decimal value. The correct values are ratios and not decimal value. The reason its happening is because excel(csv) is not handling the numbers correctly.

 

So I got a suggestion to use infile statement and read it as txt file and that should take care of the values.

angelinading_0-1584550319721.png

 

 

Following is part of the code. But it doesn't work. How should I proceed with the infile function? Thanks

data test ;
%let _EFIERR_ = 0;
infile 'data.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
format TITER $50. ;
input
TITER $
;
 if _ERROR_ then call symputx('_EFIERR_',1); 
run;
4 REPLIES 4
Tom
Super User Tom
Super User

That looks like you just copied the code that PROC IMPORT generates.  

What about it did not work?

Can you show what the file actually looks like?  You posted something that looks like a photograph of how it would look if you opened with a spreadsheet program, like Excel.

You can always just use SAS code to see what some of the lines of the file look like.  For example this program will print the first 5 lines to log with a ruler (and if there are any non-printable characters it will also show the ASCII code as two hexadecimal digits under the character).

data test ;
  infile 'data.csv' obs=5 ;
  input;
  list;
run;
angelinading
Fluorite | Level 6
Thanks Tom. The first screenshot is part of target variable from the .csv file that needs to be read into. so the thing is to change all the decimal values back to ratio, which I guess is how it looks like originally (but I don't have that on hand).
ballardw
Super User

If you open a CSV in Excel then Excel can do bad things and change values. If you don't save the file from Excel you should be okay. If you did save the file from Excel then you likely want to find another version of the file somewhere as it may well be seriously corrupted.

Note: Screen shots of CSV opened in Excel are not CSV files because of Excel reformatting values.

 

Better is to copy a few lines of data from the CSV file using an editor like Notepad, Wordpad or even the SAS editor, and them paste that into a code box opened on the forum with the </> icon.

 

Or if you are using Excel for data entry, often not a good idea, then Excel likely turned the values into TIME and the decimal represents a fraction of a day.

Tom
Super User Tom
Super User

@angelinading wrote:
Thanks Tom. The first screenshot is part of target variable from the .csv file that needs to be read into. so the thing is to change all the decimal values back to ratio, which I guess is how it looks like originally (but I don't have that on hand).

No.  First thing is that you posted an IMAGE.  A CSV file is a text file, so you can post the actual text here.  It is easier to copy and paste text than it is to generate an image and copy and paste that.

Second thing is the image is not of the CSV file. Instead if looks like the image of some spreadsheet.  If you opened the file with Excel then it will have converted to text.  Excel does all kinds of crazy stuff with text because it thinks it is helping you. 

 

If you must look at a CSV file with Excel then open Excel first and then use the Insert Data from a File feature (they keep moving it around in the menus) and then it will allow you to tell it treat each column as text.  Then you have a hope of seeing what the CSV file contained.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1594 views
  • 2 likes
  • 3 in conversation