不管是做AD还是TFL,我们经常会碰到要创建Format。当Format中条目不多时我们可以直接用PROC FORMAT来创建,但是当条目很多时,这种方法就不方便了。下面详细介绍其他几种方法:
设有数据集如下,假设要创建START为AVISITN,LABEL为AVISIT的Format:
/*方法1: CALL EXECUTE*/
data _null_;
set demo end=eof;
if _n_=1 then call execute('proc format; value vs1t');
call execute(cats(AVISITN)||' = '||quote(cats(AVISIT)));
if eof then call execute('; run;');
run;
/*方法2: macro variable*/
proc sql noprint;
select catx(' = ', cats(AVISITN), quote(cats(AVISIT))) into :fmtlst separated by ' ' from demo
order by AVISITN;
quit;
proc format;
value vs2t &fmtlst;
run;
/*方法3: CNTLIN= option*/
proc sql;
create table fmt as
select distinct 'vs3t' as FMTNAME , AVISITN as START , cats(AVISIT) as label from demo
order by AVISITN;
quit;
proc format library=work cntlin=fmt;
run;
/*方法4: FILENAME*/
proc sql;
create table fmt as
select distinct AVISITN, quote(cats(AVISIT)) as AVISIT
from demo
order by AVISITN;
quit;
/*将CODE输出到一个临时文件*/
filename code temp;
data _null_;
file code;
set fmt;
if _n_=1 then put +4 'value vs4t';
put +14 AVISITN ' = ' AVISIT;
run;
proc format;
%inc code / source2;
;
run;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有