BookmarkSubscribeRSS Feed
kaziumair
Quartz | Level 8

Hi everyone ,

I have to convert a CSV file into a SAS Dataset . The CSV file has column names containing special characters like '/' and '-' and spaces .The file contains column names like 'E/I','Sub-Category' . There are also multiple delimiters like commas ,tilde used in the file. I am using data step and the infile statement to specify multiple delimiters .

I used the validvarname=v7 option before the data step , however it treats the 'Sub-Category' column as as number list and gives the following error "Missing numeric suffix on a numbered variable list (sub-category)".

How do I import this file? 

5 REPLIES 5
japelin
Rhodochrosite | Level 12

Can you provide a csv and code to reproduce the error?
"Sub-category" is being treated as a variable.
You can't use "-" in SAS variable names.

It represents a list of numbers.

 

kaziumair
Quartz | Level 8

Hi ,thank you for responding.

 

I cannot provide the original file , created a dummy file containing column sub-category.

Also attaching the code

japelin
Rhodochrosite | Level 12

You can't use a space or - in a variable name.
Since csv is quoted, use the dsd option.
The first line is not data, so use firstobs to import from the second line.

 

how is this code.

data demo_test;
  length id 8 firstname $7 lastname $10 department $10 dateofjoining 8 subcategory $40;
	infile "C:\Users\test\df-demo.csv" dsd firstobs=2;
	input id 
		  firstname  
		  lastname  
		  department  
		  dateofjoining 
		  subcategory ;
	informat dateofjoining mmddyy10.;
	format dateofjoining date9.;
run;
kaziumair
Quartz | Level 8

I think the solution is that I will have to change the column name to adhere to sas naming conventions like the import  wizard in EG does with 'Rename columns to comply with sas naming conventions' option .  I am unable to figure out how I can do this with data step .

japelin
Rhodochrosite | Level 12

The variable names I wrote follow the SAS rules, so I don't think you need to rename them.

If you wanna rename in data step, rewrite variable name both after length and input statement.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2367 views
  • 0 likes
  • 2 in conversation