BookmarkSubscribeRSS Feed
AlexGégé
Calcite | Level 5

Hey everyone. 

 

I'm trying to import a CSV file available on internet. This file is encoding in UTF- 8. There is a problem doing this because some column-names aren't taking into account (with °, é,... symbols as example) and the 2nd column have characters and numerics values.. So, character's are replaced by some points. 

 

So, I build an empty dataset (with characters values for this second column) but I don't know how I can import this CSV file into this empty dataset, do you have any idea ? There is maybe a statement to add in proc import to write these data into my empty dataset ?

 

Thanks a lot,

 

Kind regards, 

 

Alex 

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

First try using OPTIONS VALIDVARNAME=V7;  This may fix your variable names.

 

There is no option in PROC IMPORT to insert data into existing empty table. You can use PROC APPEND with base as your empty table and data as your imported data or use INSERT INTO statements.

 

You can also use PROC HTTP to import the data from a web address directly into SAS. @ChrisHemedinger has good collection here PROC HTTP

 

Thanks,
Suryakiran
AlexGégé
Calcite | Level 5

Thanks for your answer, 

 

At the begining, I start with this: 

 

filename elect url "http://www.regardscitoyens.org/telechargement/donnees/elections/2014_municipales/municipales-2014-r%C3%A9sultats-bureaux_vote-tour1.csv"
encoding="utf-8";
/*OPTIONS VALIDVARNAME=V7;*/
proc import datafile=elect out=elect replace  dbms=csv ; 
delimiter = ";";
GETNAMES = YES; run;

 

Here is what I done for the emply table (sorry it's in French): 

/*empty table*/

proc sql;
CREATE TABLE empty
(
numero num label="N° tour",
dep char(3) label="Code département",
code num label="Code commune",
nom char(50) label="Nom de la commune",
vote num label="N° de bureau de vote",
inscrit num label="Inscrits",
votant num label="Votants",
exprimes num label="Exprimés",
numliste num label="N° de dépôt de la liste",
candidat char(20) label="Nom du candidat tête de liste",
prenom char(20) label="Prénom du candidat tête de liste",
codenuance char(10) label="Code nuance de la liste",
voix num label="Nombre de voix"
);
quit;


 

 

I try to Append it but columns names are different and so on it's not working. 

In my mind, I prepare an empty base to give to the 2nd column a character type to be able to import all row of the CSV which is changing from numeric to charactere at the end. 

 

I hope you can help me finding what I'm missing 🙂 

 

Thanks

 

Alex

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!

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
  • 2 replies
  • 2131 views
  • 1 like
  • 2 in conversation