I developed a macro that reads in all the tabs as they are. But I loop through each expected date variable (all date variables start with "SCR", "DAY", or "WEEK"), and I determine if it was properly read in as a numeric variable or incorrectly as a character variable. I then loop through the data and convert all character variables into numeric date variables. I had to add a little extra work because not all tabs had a character date in the same format. But below is a summary of what I ended up doing. Hopefully it will be helpful to someone somewhere.
%macro convert (study=);
%let table=VX%sysfunc(tranwrd(&study.,%str(-),%str(_)));
proc import out=&table. (rename=(subject_number=SUBJECT)) datafile="S:\cdm\Programming\Adhoc\COVID19\COVID19_Cumulative DET_16MAR20.xlsx" dbms=excelcs replace;
scantext=yes;
usedate=yes;
scantime=yes;
sheet="&study.";
run;
%let scr_exist=0;
%let day_exist=0;
%let week_exist=0;
proc sql noprint;
select '1' into :scr_exist from sashelp.vcolumn where libname='WORK' & memname="&table." & index(upcase(name),'SCR')>0;
select '1' into :day_exist from sashelp.vcolumn where libname='WORK' & memname="&table." & index(upcase(name),'DAY')>0;
select '1' into :week_exist from sashelp.vcolumn where libname='WORK' & memname="&table." & index(upcase(name),'WEEK')>0;
quit;
proc sql noprint;
select left(put(count(name),3.)) into :ncharvar from sashelp.vcolumn where libname='WORK' & memname="&table." & type='char' & (index(upcase(name),'SCR')>0 | index(upcase(name),'DAY')>0 | index(upcase(name),'WEEK')>0 | index(upcase(name),'ETT')>0);
select name into :charvar1-:charvar&ncharvar. from sashelp.vcolumn where libname='WORK' & memname="&table." & type='char' & (index(upcase(name),'SCR')>0 | index(upcase(name),'DAY')>0 | index(upcase(name),'WEEK')>0 | index(upcase(name),'ETT')>0);
select label into :charlab1-:charlab&ncharvar. from sashelp.vcolumn where libname='WORK' & memname="&table." & type='char' & (index(upcase(name),'SCR')>0 | index(upcase(name),'DAY')>0 | index(upcase(name),'WEEK')>0 | index(upcase(name),'ETT')>0);
quit;
data &table. (drop=ett %do i=1 %to &ncharvar.; &&charvar&i.._temp %end;);
set &table. (rename=( %do i=1 %to &ncharvar.;
&&charvar&i.=&&charvar&i.._temp
%end;));
%do i=1 %to &ncharvar.;
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'JAN','1');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'FEB','2');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'MAR','3');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'APR','4');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'MAY','5');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'JUN','6');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'JUL','7');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'AUG','8');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'SEP','9');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'OCT','10');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'NOV','11');
&&charvar&i.._temp=tranwrd(upcase(&&charvar&i.._temp),'DEC','12');
&&charvar&i.=mdy(input(scan(&&charvar&i.._temp,2,'/'),??best.),input(scan(&&charvar&i.._temp,1,'/'),??best.),input(scan(&&charvar&i.._temp,3,'/'),??best.));
format &&charvar&i. date9.;
label &&charvar&i.="&&charlab&i.";
%end;
if ett^=. then delete;
run;
%mend convert;
... View more