*filename pgm '/mscdc/sasmacro/import.sas'; /******************************************************************** * NAME: import John Blodgett, OSEDA, U. of Missouri * * FUNCTION: interface for import and export procs * * * ********************************************************************/ %GLOBAL REVDATE; %LET REVDATE=20Nov99; *<----DATE OF LAST REVISION; /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO import ( out=, /* SAS data set to be created */ setout=, /* alias for out */ datafile=, /* the external file being imported from. Can be a fileref. */ file=, /* alias for datafile */ table=, /* the table to be imported from or exported to. */ dbms=, replace=1, getnames=0,range=,sheet=,delimiter=,getdeleted=0, database=, dbpwd=,memosize=,pwd=,uid=,wgdb=, delimiter=, dlm= /* alias for delimiter */ ); /* END */ %PUT %STR( ); %PUT ***************************************************************; %put * IMPORT macro Rev &revdate begin execution *; %put * Missouri State Census Data Center *; %PUT ***************************************************************; %PUT %STR( ); %local null; %*--null value-; %local error; %let error=0; %local fdatafil ftable fout temp rc path; %if %quote(&datafile) eq &null %then %if %quote(&file) ne &null %then %let datafile=&file; %if %quote(&datafile) eq &null %then %let fdatafil=0; %else %let fdatafil=1; %if %quote(&table) eq &null %then %let ftable=0; %else %let ftable=1; %let temp= %eval(&fdatafil + &ftable); %if &temp ne 1 %then %do; %if &temp=0 %then %put ****At least one of parms DATAFILE or TABLE must be specified****; %if &temp=2 %then %put ****Cannot specify both DATAFILE and TABLE parms - mutually exclusive****; %let error=1; %goto endmac; %end; %if %quote(&database) eq &null %then %let fdatabas=1; %else %let fdatabas=0; %if &ftable %then %if not &fdatabas %then %do; %put *****TABLE parm specified but not DATABASE parm**** ; %let error=1; %goto endmac; %end; %if &out eq &null %then %if %quote(&setout) ne &null %then %let out=&setout; %if &out eq &null %then %do; %put *****Required parm OUT not specified*****; %let error=1; %goto endmac; %end; %*--check to see if datafile is a fileref and, if so, substitute the fully qualified name--; %if %index(&datafile,%str(.)) eq 0 %then %do; %*--no dot in value indicates a fileref but we shall double check--; %let rc= %sysfunc ( fileref(&datafile)); %if &rc=0 %then %do; %let path= %sysfunc( pathname(&datafile)); %put ---FYI: Import detected a fileref as value of datafile and has substituted the path value:; %put &path; %let datafile="&path"; %end; %end; %*--Ready to generate some code--*; proc import %if &fdatafil %then %str ( datafile= &datafile ); %else %if &ftable %then %str ( table= &table ); out=&out %if %quote(&dbms) ne &null %then %str( dbms=&dbms ) %if &replace %then %str( replace ); ; %if %quote(&delimiter) eq &null %then %if %quote(&dlm) ne &null %then %let delimiter=&dlm; %if %quote(&delimiter) ne &null %then %str( delimiter=%delimiter ;); %*** getnames=0,range=,sheet=,delimiter=,getdeleted=0, %if %quote(&getnames) ne &null %then %str( getnames=&getnames ;); run; %endmac: %if &error %then %put ****Importmacro detected an error and will not generate any proc import code***; %MEND import;