Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in unusual var names from csv

Status
Not open for further replies.

SPhill

Programmer
Sep 17, 2003
32
0
0
GB
Hello, I've got a problem with an input file which I've been asked to strip out some policy numbers. The problem arises with the first variable being called '!' i.e.

!,polref
*,1
*,2
*,3
*,4
*,5

PROC IMPORT OUT= WORK.exclam
DATAFILE= "C:\Scott\PeskyExclamation.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;

proc print;
run;

Obs _ polref

1 * 1
2 * 2
3 * 3
4 * 4
5 * 5

SAS substitutes the original '!' and replaces it with an underscore '_'. Does anyone know how to get round this, I really need to carry the exclamation variable through into a proc export back into a csv file after I've stripped my policy numbers out, must be in the same order as well. Hope I'm making sense here?

Thanks

SPhill
 
Read in the first record as if it is data, change getnames=YES to getnames=NO, change DATAROW to 1.

That should do it.

Alternatively, don't use proc import, write a datastep with an import statement. It's a bullet proof way of doing it, but it does mean you have to manually code in the columns names etc (unless you're able to write some reasonably complex macro code).

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks for the reply, I've managed to fix this by using:

options validvarname=any ;
proc datasets library=work;
modify &&fname&i;
rename _ = '!'n ;
run;

I've got quite a few csv files with different headers so didn't fancy lots of proc imports.

Thanks

SP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top