%macro doalink( Revdate=%str(3/9/2004 4:00PM), /* This macro is invoked to create an entry (observation) in the system.alinks dataset. Such entries will be used as the source of the information contained in our A to Z index pages (another macro, %genalhtm, will be used to access the system.alinks dataset and generate the various alinks html pages). See also the alinks_attribs.sas module (included by this module when initializing) in the /pub/sascode directory. That module specifies the lengths of the SAS variables corresponding to the parms of the same name used to assign them values. Additional comments there as well. Only documentation is the comments there and here. Originally coded circa 2004 by John Blodgett, OSEDA/Missouri Census Data Center. */ mode=, /* Values are initialize, append and update. Blank says to assign update or append depending on whether the observation already exists. */ dataset=system.alinks, /* probably should never override default except maydo to do a test. This is the 2-level SAS dataset that will be updated or created with the data about the links */ alphakey=, /* the parms are named for the variables they correspond to. See p:\mcdc\Specifications for Creating alinks.doc on oseda network drive for details. */ website=mcdc, url2=, HyperText=, Level=0, Across=0, Htext=,Htext2=,Htext3=, ExpDate=, /* Specify value in mmddyy format or mmyy */ expires=, /* alias for expdate */ CodedBy=, debug=0); %global coder; %local null; %let null=%str(); %local errmsg; %let mode=%lowcase(&mode); %if &debug %then %put doalink macro, revised &revdate, begin execution with mode=&mode AlphaKey=&alphakey; %*---Process aliases-----; %if %nrbquote(&expires) ne %then %let expdate=&expires; %if &mode=initialize %then %do; %if %sysfunc(exist(&dataset))=1 %then %do; %let errmsg=%str(Initialize mode specified but &dataset already exists); %gotto flag_it; %end; %else %goto _init; %end; %if &alphakey eq &null %then %let errmsg=%str(Required parameter AlphaKey was not specified); %local datalib datamem; %if &dataset eq &null %then %let errmsg=%str(Required parameter dataset was not specified); %else %do; %let datalib=%scan(&dataset,1,%str(.)); %let datamem=%scan(&dataset,2,%str(.)); %if &datalib=system %then %do; %*--Only the default libref results in us generating the libname stmt--; libname system '/pub/data/system'; %end; %end; %flag_it: %if %superq(errmsg) ne &null %then %do; %*<======================; %let errword_=ERROR; %put *****&errword_.: Detected by doalink macro: ; %put &errmsg; %put %str( ) *****No output will be generated*****; %goto endmac; %end; %if &mode eq &null %then %do; %*---assign mode as either append or update depending on whether the AlphKey entry is already in the alinks dataset.---; data _null_; AlphaKey="&alphakey"; set &metaset key=alphakey; if _iorc_=0 then mode='update'; else mode='append'; call symput('mode',mode); put 'Mode has been assigned as ' mode; stop; run; %end; %_init: %if &mode=initialize %then %do; data &dataset(label="Each obs documents 1 link on our A to Z links pages."); %include sascode('alinks_attribs.sas'); put / '***The notes regarding uninitialized variables in this step can be safely ignored***'/; stop; run; proc datasets lib=%scan(&dataset,1) nolist; modify %scan(&dataset,2); index create alphakey / unique; quit; %goto endmac; %end; data _&alphakey; %*---Create a separate set with the alinks metadata --; if 0 then set &dataset; %*<---just to establish program data vector--; length _errmsg $512; AlphaKey="&alphakey"; WebSite="&website"; select (WebSite); when('mcdc') WebSite='mcdc.missouri.edu'; when('mcdc') WebSite='mcdc.missouri.edu'; when('oseda') WebSite='oseda.missouri.edu'; when('census') WebSute='www.census.gov'; otherwise; end; url2="&url2"; HyperText=urlencode("&hypertext"); Level=&level; Across=&across; Htext="&htext"; Htext2="&htext2"; Htext3="&htext3"; if length("&expdate")=5 then ExpDate=input(lowcase("expdate"),monyy5.); else if length("&expdate")=6 then ExpDate=input("expdate",mmddyy6.); Codedby="&codedby"; if Codedby=' ' then CodedBy="&coder"; if _errmsg ne ' ' then link flagerr; output; drop _:; stop; flagerr: put /'********Error detected -- no metadata output will be generated. ERR' 'OR:' / _errmsg ; abort abend; run; %if &mode=append %then %do; %if &debug %then %put New metadata will be appended to &metasetout; proc append data=_&alphakey base=&dataset; run; %end; %else %if &mode=update %then %do; data &dataset; update &dataset _&alphakey; by alphakey; run; %end; *---regenerate the alphakey index--- ??? ---**; proc datasets lib=system nolist; modify alinks; index create alphakey / unique; quit; %endmac: %mend doalink;