Desktop productivity for business analysts and programmers

How to read CSV file data with column names that contain embedded blanks.

Reply
Contributor PQK
Contributor
Posts: 21

How to read CSV file data with column names that contain embedded blanks.

Dear Forum,

I can accurately read CSV file data using EG4.3 and IMPORT (File > Import Data) even though the file contains a first line of column names with embedded blanks, dashes (-), parentheses and periods.

However, I am learning how to program in SAS and would like to replace this step with code. I can create working code with DATA, INFILE, INPUT statements and so forth using standard column names.

The problem is how to get SAS to read column names when the column names include spaces, parentheses etc.

If I borrow the 'column name'n convention EG4.3 generates in the INPUT statement from the IMPORT Wizard code, I either get a tableview with ??? in each cell (in the case of EG4.3) or I get the error "The name is not a valid SAS name." if I run my code in SAS9.2 using the 'column name'n convention.

Even if I cut and paste the entire EG4.3 code from the IMPORT step into a seperate code program and run it in a seperate project, I still get a tableview with ??? in each cell.

What I'm I doing wrong?
Community Manager
Posts: 2,697

Re: How to read CSV file data with column names that contain embedded blanks.

You might need to set this option:

options validvarname=any;

EG sets it by default, but if you are running in SAS Display Manager or batch, it's not the default setting.

http://support.sas.com/kb/14/661.html

Chris
Contributor PQK
Contributor
Posts: 21

Re: How to read CSV file data with column names that contain embedded blanks.

Chris,

Thank you for your reply to my post.

It turned out that the problem with ??? in each cell of my tableview was due to the length and format of various numeric/character variables. After conducting a careful trial and error analysis of each variable I was able to narrow down the issue to a view problem variables.

Your suggestion in regards to changing the VALIDVARNAME option worked perfectly for base SAS (9.2). Although the default in EG4.3 is already set to VALIDVARNAME=ANY, the option in Base SAS was set to V7. After changing this option (and my changes to the length and format mentioned above), both Base SAS and EG4.3 were able to produce the dataset from code.

Best Regards,

PQK
Ask a Question
Discussion stats
  • 2 replies
  • 1093 views
  • 0 likes
  • 2 in conversation