Since the data is in a CSV file there is no need to "IMPORT" it. Instead you can just READ the file directly into a dataset. Then you can use any NAME you want for the data in the columns with those headers. You can put the long strings in the header line into the LABEL of the variable.
data want;
infile 'have.csv' dsd firstobs=2 truncover ;
length vacants individuels 8;
label vacants = 'Parc mondial - Taux de logements vacants* (en %)'
individuels = 'Parc mondial - Taux de logements individuels (en %)'
;
input vacants individuels;
run;
If you need a tool to try and make GUESSes about how to read in a CSV file instead of using PROC IMPORT try using this macro: https://github.com/sasutils/macros/blob/master/csv2ds.sas
It can handle creating unique names for columns whose headers are the same for the first 32 bytes. Plus it will always attach a label to the variable when the column header is not exactly the same as the name of the variable it creates.
Let's make an example and test them.
filename csv temp;
options parmcards=csv;
parmcards4;
id,Parc mondial - Taux de logements vacants* (en %),Parc mondial - Taux de logements individuels (en %)
1,10,20
2,20,30
3,25,45
;;;;
options validvarname=any;
proc import dbms=csv file=csv out=import replace;
run;
%csv2ds(csv,out=csv2ds,replace=yes)
proc compare data=import compare=csv2ds listall;
run;
When you run with VALIDVARNAME=ANY you will still get those non-standard variable names that will require using name literals to reference, but will will get a numeric suffix on the second one so that the names are different.
Listing of Variables in WORK.CSV2DS but not in WORK.IMPORT
Variable Type Length Label
Parc mondial - Taux de logemen_1 Num 8 Parc mondial - Taux de logements individuels (en %)
And if you run with VALIDVARNAME=V7 (which I encourage so that SAS does not generate non-standard variable names) then %CSV2DS will actually be able to make more descriptive long names since it will collapse the ' - ' into a single underscore so that the names will differ in the 32nd byte.
Listing of Variables in WORK.IMPORT but not in WORK.CSV2DS
Variable Type Length Format Informat
Parc_mondial___Taux_de_logements Num 8 BEST12. BEST32.
VAR3 Num 8 BEST12. BEST32.
Listing of Variables in WORK.CSV2DS but not in WORK.IMPORT
Variable Type Length Label
Parc_mondial_Taux_de_logements_v Num 8 Parc mondial - Taux de logements vacants* (en %)
Parc_mondial_Taux_de_logements_i Num 8 Parc mondial - Taux de logements individuels (en %)
You can see more of the advantages of using %CSV2DS() by reading the comments in the code.
Differences from PROC IMPORT
- Supports header lines with more than 32,767 characters
- Supports ZIP and GZIP source files
- Generates unique variable names by adding numeric suffix
- Does not overestimate maxlength when longest value is quoted
- Does NOT force character type if all values are quoted
- Generates label when generated variable name is different than header
- Supports NAMEROW option
- Supports numeric fields with special missing values (MISSING statement)
- Does not attach unneeded informats or formats
- Allows overriding calculated metadata
- Allow using random sample of rows to guess metadata
- Generates more compact SAS code
- Generates analysis summary dataset and raw data view
- Saves generated SAS code to a file
- Forces DATE and DATETIME formats to show century
- Difference in generated V7 compatible variable names
- Replaces adjacent non-valid characters with single underscore
... View more