sas - Proc Import. Importing Character values as "Blank" from excel files -
i trying import multiple excel files using code below. there column in each excel file has both numeric , text values proc import importing numeric values, , put text values blank ('.').
can me issue? much.
%let subdir=s:\temp\; filename dir "&subdir.*.xls"; data new; length filename fname $ 32767; infile dir eof=last filename=fname; input ; last: filename=fname; run; proc sort data=new nodupkey; filename; run; data null; set new end=last; call symputx(cats('filename',_n_),filename); call symputx(cats('dsn',_n_),scan(scan(filename,7,'\'),1,'.')); if last call symputx('nobs',_n_); run; %put &nobs; %macro import; %do i=1 %to &nobs; proc import datafile="&&filename&i" out=&&dsn&i dbms=excel replace; sheet = "sheet1"; getnames=yes; mixed=yes; run; %end; %mend import; %import
the best way control data types in imported excel work book use dbsastype
data set option libname. useful when dealing other data types (like datetime , time values).
for example, let's assume affected column named my_var , should read character max length of 30. , let's assume have spreadsheet column named start_time contains excel coded date , time stamp. macro might revised this:
libname x "&&filename&i"; data &&dsn&i; set x.'sheet1$'n(dbsastype=(my_var=char30 start_time=datetime)); run; libname x clear;
as long know name of excel column causing problem, should work well.
Comments
Post a Comment