The following is the code I wrote before to generate a PDF version of define.xml . Hope could help you a little bit.
%let path=%sysfunc(prxchange(s/[^\\]+$//,1,%sysget(SAS_EXECFILEPATH)));
options orientation=landscape validvarname=any varlenchk=nowarn nonumber nodate ; *nocenter;
/*原始数据库 的路径*/
libname data v9 "&path.SAS" access=readonly;
/*研究标识*/
%let study_id= C20LBE003;
/*第一页的title*/
%let title= 奥美拉唑胶囊-非CDISC标准原始数据库 ;
/*版本*/
%let version= 01.1 / 2020-11-12 ;
/*导入 附加 的数据说明 - 结构 , 来源 , 外部词典*/
proc import datafile="&path.数据说明.xlsx" out=add_table dbms=xlsx replace;
sheet='表单';
run;
proc import datafile="&path.数据说明.xlsx" out=add_var dbms=xlsx replace;
sheet='变量';
run;
proc import datafile="&path.数据说明.xlsx" out=add_dictionary dbms=xlsx replace;
sheet='外部词典';
run;
/*产生字典表*/
proc sql;
create table define_xml_tables as
select a.*,b.基本结构描述 ,1 as _id_ from /*产生 _id_ 变量,用于去掉 书签'表1'*/
(
select memname,memlabel
from dictionary.tables
where libname='DATA' and memname ne 'CODELIST'
) as a left join add_table as b
on a.memname=b.数据集名
order by 1;
create table define_xml_columns as
select a.*,b.来源 label='来源/方法/注释',1 as _id_ from /*产生 _id_ 变量,用于去掉 书签'表1'*/
(
select memname ,name label='变量',label label='标签/描述',type label='类型',length label='长度或显示格式',varnum label='变量序号'
from dictionary.columns
where libname='DATA'
) as a left join add_var as b
on a.memname=b.数据集名 and a.name=b.变量名
order by 1,2;
quit;
/*处理 Code List, 一个变量 对应 一行*/
proc sort data=data.codelist out=codelist ;by DS FIELD;run;
data codelist_1;
do until(last.FIELD);
set codelist;
by DS FIELD;
length dictionary $ 400;
dictionary=catx(',',dictionary,cats('"',value,'"="',TEXT,'"'));
end;
keep DS FIELD dictionary;
label dictionary='受控术语或ISO格式';
run;
/*将 CodeList 拼进 字典表 define_xml_columns*/
data define_xml_columns_1;
merge define_xml_columns(in=ina) codelist_1(rename=(ds=memname FIELD=name));
by memname name;
if ina ;
run;
proc sort data=define_xml_columns_1 sortseq=linguistic(numeric_collation=on); by memname varnum;run;
proc sort data=codelist sortseq=linguistic(numeric_collation=on); by DS FIELD;run;
/* 取有 值的 CodeList*/
data codelist_2;
set define_xml_columns_1 ;
if not missing(dictionary);
run;
/*添加 '位置' 列*/
data define_xml_tables;
set define_xml_tables;
length position $ 40 ;
memname=lowcase(memname);
position=cats(memname,'.xpt');
label position='位置';
run;
/*产生 _id_ 变量,用于去掉 书签'表1'*/
data codelist;
set codelist;
_id_=1;
run;
/*产生 _id_ 变量,用于去掉 书签'表1'*/
data add_dictionary;
set add_dictionary;
_id_=1;
run;
ods _all_ close;
ods pdf file="&path.define_xml.pdf" style=sasweb ;
footnote j=l "版本: &version " j=r '(*ESC*){thispage} / (*ESC*){lastpage}';
title j=l "&title" j=r "研究标识: &study_id";
ods proclabel= "&title" ;
/*打印 第一张 表*/
proc report data=define_xml_tables(where=(memname is not missing)) nowd contents='' split='*' style(report)={outputwidth=100% rules=all};
define memname/display '数据集';
define memlabel/display '描述';
define _id_/order noprint;
compute memlabel;
rtag = "#"||strip(memname);
call define(_col_,'url',rtag);
call define(_col_,'style','style={foreground=blue}');
n+1;
if mod(n,2)=1 then call define(_row_,'style','style={background=verylightgrey}');
endcomp;
compute position;
call define(_col_,'url',".\厦门恩成- 艾司奥美拉唑镁碳酸氢钠胶囊-非CDISC标准原始数据库-20201123\3.原始数据库\XPT\");
call define(_col_,'style','style={foreground=blue}');
endcomp;
break before _id_/page contents='';
run;
/*打印 各表结构*/
data _null_;
set define_xml_tables(where=(memname is not missing));
call execute(catt('ods pdf anchor="',strip(memname),'" startpage=now ;
ods proclabel="',memlabel,'";
title j=l "',memlabel,'" j=r "研究标识: &study_id";',
'proc report data=define_xml_columns_1( where=(memname="',upcase(memname),'")) nowd split="*" contents=""
style(report)={outputwidth=100% rules=all}
style(header)={font_weight=bold} ;
columns memname name label type length dictionary 来源 _id_;
define memname/display noprint;
define _id_/order noprint;
compute dictionary;
rtag = "#"||strip(name);
call define(_col_,"url",rtag);
call define(_col_,"style","style={foreground=blue}");
n+1;
if mod(n,2)=1 then call define(_row_,"style","style={background=verylightgrey}");
endcomp;
break before _id_/page contents="";
run;title " "; ' ));
run;
/*打印 控制项 Code List*/
data _null_;
set codelist_2(where=(memname is not missing));
call execute(catt('ods pdf anchor="',strip(name),'" startpage=now;
ods proclabel="',label,'";
title j=l "',label,'" j=r "研究标识: &study_id";',
'proc report data=codelist( where=(DS="',upcase(memname),'" and FIELD="',upcase(name),'")) nowd split="*" contents=""
style(report)={outputwidth=100% rules=all}
style(header)={font_weight=bold} ;
define ds/display noprint;
define FIELD/display noprint;
define value/display "允许值(代码)";
define text/display "显示值(解码)";
define _id_/order noprint;
compute ds;
n+1;
if mod(n,2)=1 then call define(_row_,"style","style={background=verylightgrey}");
endcomp;
break before _id_/page contents="";
run; title " "; ' )); /* 或者 title; */
run;
/*打印 外部词典*/
title j=l "外部词典" j=r "研究标识: &study_id";
ods proclabel= "外部词典" ;
proc report data=add_dictionary(where=(参考名称 is not missing)) nowd contents='' split='*' style(report)={outputwidth=100% rules=all};
define _id_/order noprint;
break before _id_/page contents=''; /*去掉左边标签*/
run;
title ' ';
ods pdf close;
... View more