I am trying to import a large CSV file (approximately 7k variables and 355 observations). Proc Import stops reading variable names after ~2k columns, I'm not really sure why. I have found that using infile will get me the whole csv into SAS, but the variable names are in the first row, and the variables are named v1-vn. I just need to take the variable names from the first row, and modify/rename my dataset using those.
So far I have: Used infile and transpose to get all of my variable names into one column in a separate dataset. Used proc sql to select this column into a list. Banged my head against my keyboard for a day and a half using macros and this list to try and modify the original variable names.
I have used the code below in my most recent (unsuccessful) attempt. Bear in mind that with ~7k variables I cannot rename them by hand, or even an appreciable fraction of them. I need to use do loops or macros in some way to do this, or else get infile to properly read in variable names.
data LabImportRaw;
length v1-v6876 $300;
infile 'C:\xxxxxxxxxxxx\LabImportListing.csv' delimiter=',' firstobs=2 missover lrecl=250000;
input v1-v6876 ;
run;
data LabImportVNames;
length v1-v6876 $300;
infile 'C:\xxxxxxxxxx\LabImportListing.csv' delimiter=',' obs=1 missover lrecl=250000;
input v1-v6876 ;
Array VNames(6876) v1-v6876;
run;
proc transpose
data=LabImportVNames
Out=LabImportVNames;
var v1-v6876;
run;
*Create a list of new variable names;
proc sql;
select Col1
into :renamelist
from LabImportVNames;
quit;
*Create Rename Macro;
%macro rename(oldvarlist, newvarlist);
%let k=1;
%let old = %scan(&oldvarlist, &k);
%let new = %scan(&newvarlist, &k);
%do %while(("&old" NE "") & ("&new" NE ""));
rename &old = &new;
%let k = %eval(&k + 1);
%let old = %scan(&oldvarlist, &k);
%let new = %scan(&newvarlist, &k);
%end;
%mend;
*Do the renames;
proc datasets lib=work;
modify LabImportRaw;
%rename(v1-v6786, renamelist)
run;