BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mcmaxwell
Fluorite | Level 6

Hello, I am trying to upload a CSV file that includes a column labeled "Letter_Grade" that contains the grades A, A-, B+, B, B-, etc. When I upload the CSV to SAS Studio, it drops all of the pluses and minuses and only keeps the letter. I tried changing the data type in excel to "text" rather than "general" but that did not solve the problem. Does anyone know why this is happening, and how to fix the problem? I have not had this problem with similar CSV files. Below is the code I am using: 

/** Import the CSV file. **/  
FILENAME CSV "/folders/myfolders/sasuser.v94/BIO 121 2015-2020/2018 Gradebook.csv" TERMSTR=CRLF;  
PROC IMPORT DATAFILE=CSV  
		    OUT=Gradebook  
		    DBMS=CSV  
		    REPLACE;  
RUN;  
 
proc print data=Gradebook; run;

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Can you post the first 20 or so lines of that CSV?

Or alternately, run the proc import code and then copy from the LOG the data step generated and then paste into a text box opened on this forum with the </> icon.

 

Proc Import only uses a very few lines of data to set types. I suspect that none of the grades in the first few lines are the ones with the A+ or such. If you see the INFORMAT for that variable to show something like:

 

Informat Letter_grade $1. ;

then SAS set the property to one character because that is what it saw in the first few lines. If that is what happened the easy fix is to either add a statement:

Guessingrows=max;

to proc import, which will force the procedure to examine more rows or copy the data step to the editor, clean up things like numbers and set the Informat for the variable to $2. Then use the data step to read the data.

View solution in original post

3 REPLIES 3
ballardw
Super User

Can you post the first 20 or so lines of that CSV?

Or alternately, run the proc import code and then copy from the LOG the data step generated and then paste into a text box opened on this forum with the </> icon.

 

Proc Import only uses a very few lines of data to set types. I suspect that none of the grades in the first few lines are the ones with the A+ or such. If you see the INFORMAT for that variable to show something like:

 

Informat Letter_grade $1. ;

then SAS set the property to one character because that is what it saw in the first few lines. If that is what happened the easy fix is to either add a statement:

Guessingrows=max;

to proc import, which will force the procedure to examine more rows or copy the data step to the editor, clean up things like numbers and set the Informat for the variable to $2. Then use the data step to read the data.

andreas_lds
Jade | Level 19

Have a look at the log. There you should find multiple lines setting the metadata for the variable Letter_Grade.The length-statement sets the number of chars the variable can contain, most likely proc import decided to set the length to one. I recommend using a data step to read csv-files. This may be more work, but in the long run this is the only way to have full control over the created datasets. And you should not open csv-files with excel, of course, because excel always does some dark magic so that often you don't see what's really in the file.

Kurt_Bremser
Super User

Don't bother with PROC IMPORT when reading CSV files. They time you waste fixing things every time you read the file outweighs the time you spend writing the data step once.

See Maxim 31.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1033 views
  • 0 likes
  • 4 in conversation