%macro genparms(/* this macro helps in building datasets datasets by generaring the SAS code to invoke the doset utility macro. It can use an existing datasets dataset, select members, to help modify existing entries. It creates a subset of the current datasets dataset and invokes proc fsedit to allow the user to modify the data. It then reads the resulting temp dataset and generates a SAS coding file that can be submitted. MUST BE RUN IN INTERACTIVE mode since it invokes the fsedit proc. It generates and runs a job from /SAS_temp/&filetype._invoke_dosets.sas . J Blodgett, oseda, Nov. 2004 */ filetype, /* the filetype we are generating metadata for. Subdirectory of /pub/data */ memnames, /* specify 1 or more member (dataset or view) names that you want to generate doset invokes for. The macro will try to access &filetype..datasets and select observations from there that have matching memname values. This allows you to edit a temporary parms dataset that displays previously specified metadata for these members. For new datasets you do not need to specify any names since these will not be found on the current datasets dataset. Always specify at least 1 memname, even if it is new (no current datasets obs for it.) */ coder= , /* identify the coder */ gendshtm=0, /* specify gendshtm=1 to have the generated job include invoking the macro of the same name to regenerate the Datasets.html web page in the filetype directory */ runprocc=1, /* value is passed as the value of the like-named parm on the gendshtm macro */ runjob=1, /* specify runjob=0 if you do NOT want to run the generated job. */ datadir=%str(/pub/data), /* the root of our data dir. See libname &filetype stmt below */ skeleton=0, /* specify a value of 1 to cause a skelteon datasets dataset to be created. Probably do not need this parm unless starting over since the program will detect the non-existence of a datasets dataset and will turn this flag on (to value 1). */ revdate=11/27/2004); /* revision date for this macro */ libname &filetype "&datadir/&filetype"; filename jobout "/SAS_temp/&filetype._invoke_dosets.sas" ; %local errors; %let errors=0; %let ds2=&filetype..datasets; %if &skeleton=0 %then %if %sysfunc(exist(&ds2))=0 %then %do; %put ****Skeleton=1 being specified because no &ds2 dataset was found****; %let skeleton=1; %end; %if &skeleton %then %do; data &filetype..dosetparms; if 0 then set '/pub/data/system/setparms'; *---establishes the variables for the dataset---; libname="&filetype"; memname="%scan(&memnames,1)"; put "Skeleton &filetype..dosetparms dataset generated"; output; stop; run; %end; %else %do; data &filetype..dosetparms; if 0 then set system.setparms; keep coder -- _OverflowText; %if %superq(memnames) ne %str() %then %let memlist=csqlist(&memnames); set &filetype..datasets (keep=libname memname refset memlabel filetype geouniv units sortprio years keywords description usagenotes keyvars keyfmats keyquals keyidvars means mweights datasource sortedby indexedby createpgm createlib subtype setgroup contactemail contactname varset urlmeta rename=(refset=template)); %if %superq(memnames) ne %str() %then %do; where memname in (&memlist); %end; run; %end; *--initialize the output job, just in case something goes wrong in fsedit step, we do not try to run an old version.--; data _null_; file jobout; when=datetime(); put +1 '/* ------------------------------------------------------------------------------------------' / +1 " This job generated using the genparms.sas macro " when datetime16. ". Coder is &coder.." / +1 ' ------------------------------------------------------------------------------------------*/ '; stop; run; *---invoke the fsedit procedure to edit the dosetparms dataset---; proc fsedit data=&filetype..dosetparms nr=60 nc=132 stcol=1 strow=1; run; data _null_; set &filetype..dosetparms; where coder ne ' '; *<-----this is how we distinguish obs that have been edited---; where also libname ne ' ' and memname ne ' '; *--required items---; length L $4000; L='%'||'doset(libname='||trim(libname)||',memname='||trim(memname)||','; link output; length _parmval $4000 _parm $32; %macro _doparms(parmlist); %local i parm; %let i=1; %let parm=%scan(&parmlist,1); %do %until(&parm eq %str()); _parm="&parm"; _parmval=&parm; link ckparm; if _parmval ne ' ' then link output; %let i=%eval(&i+1); %let parm=%scan(&parmlist,&i); %end; %mend _doparms; %_doparms(template MemLabel filetype geouniv units sortprio years keywords description usagenotes keyvars keyfmats keyquals keyidvars means mweights datasource sortedby indexedby createpgm createlib subtype setgroup contactemail contactname varset urlmeta ); L='debug=0);'; link output; put ' '; *--a blank line between invocations of the doset macro--; return; output: file jobout mod; if L=' ' then do; *---remove consecutive multiple blanks from parameter values----*; _parmval=compbl(_parmval); L=trim(_parm)||'='; needs_quoting= indexc(_parmval,'%&(),='); if needs_quoting then L=trim(L)||'%nrbquote('; L=trim(L)||trim(_parmval); if needs_quoting then L=trim(L)||'),'; else L=trim(L)||','; if length(L) gt 132 then do until(length(L) le 132); put L $char132. ; *<---carriage return used to break up lines---; L=substr(L,133); end; end; put L $char132. ; L=' '; return; ckparm: *---we look for an odd number of double quotes or a different number of left vs right parentheses---; length _msg $64; _msg=' '; if mod ( length(_parmval) - length ( compress(_parmval,'"')), 2)=1 then _msg='Odd number of double quotes'; else if (length(_parmval) - length (compress(_parmval,'('))) ne (length(_parmval) - length (compress(_parmval,')'))) then _msg='Unbalanced parentheses'; if _msg ne ' ' then do; file log; put '***Check value of paramter spec:' _parm '=' _parmval '. ***' _msg ' ***'; call symput('errors',1); file jobout; end; return; run; %if &gendshtm %then %do; data _null_; file jobout mod; put " proc sort data=&filetype..datasets out=bysortprio; " / ' by sortprio; run;' / " proc datasets library=&filetype nolist;" / ' modify datasets;' / ' index delete dataset memname;' / ' index create dataset=(libname memname) / unique;' / ' index create memname;' / ' quit;' / ' %gendshtm(' "libname=&filetype,debug=1,runprocc=&runprocc);" ; run; %end; %if &runjob and &errors=0 %then %do; %include jobout; %end; %mend genparms;