A RENAME
statement can be used to change the default column names assigned by PROC IMPORT
when GETNAMES=NO
.
Example:
Presume the column names in the Word document were copy and pasted into SAS datalines
filename onlydata temp;
* create some sample data;
data _null_;
file onlydata dlm=',';
set sashelp.class(obs=3);
put name age sex height weight;
run;
* log the sample data just to get a look-see;
data _null_;
infile onlydata;
input;
put _infile_;
run;
* IMPORT the data only datafile, no names to get!;
* default column names are VAR1 to VAR<n>;
proc import file=onlydata replace out=onlydata dbms=csv;
GETNAMES=NO;
run;
* presume the column names in the Word document are in the correct order
* (matching the data file) and were copy & pasted into the datalines;
data column_names(label="From WORD document");
length name $32;
input name;
datalines;
name
age
sex
height
weight
run;
* Construct the oldname=newname source code pairs for a RENAME statement;
data _null_;
set column_names end=last_column;
length pairs $32000;
retain pairs;
pairs = catx(' ', pairs, catx('=', cats('var',_n_), name));
if last_column then
call symput ('pairs', trim(pairs));
run;
* use Proc DATASET to modify the header portion of the datas set;
* will not rewrite the entire data set;
proc datasets nolist lib=work;
modify onlydata;
rename &pairs;
run;
quit;
%let syslast = onlydata;
log image of the look-see
data set with default PROC IMPORT
column names
data set after RENAME
statement applied via PROC DATASETS