上个月的今天,我从南到北,从深圳奔赴帝都参加了一个制药行业软件用户组2016中国区年会(PharmaSUG China 2016)。听了两天的报告,收获不少。有幸见到SAS绘图大神Sanjay Matange,可惜当时忘记了要合影。这个名字可能大家不熟悉,但是他的博客Graphically Speaking我相信很多人有看过。在众多报告中,印象较深的是这个。作者分享了几个很有用的SAS技巧,比如自动打开所标记的数据集、自动获取某个变量的值。可惜没有分享源程序,所以我写了三个小程序,实现了自动打开数据集、执行选中程序并打开生成的数据集以及复制变量值。
%macro markdsn();
gsubmit "
dm 'wcopy';
filename clip clipbrd;
data _null_;
infile clip;
input;
call execute('dm ""vt '||_INFILE_||';"" continue ;');
run;
filename clip clear;";
%mend markdsn;
%macro markcode();
gsubmit "
dm 'wcopy';
filename clip clipbrd;
data _null_;
infile clip end=eof;
input;
call execute(_INFILE_);
if eof then call execute('%nrstr(dm ''vt &syslast;'' continue ;)');
run;
filename clip clear;";
%mend markcode;
%macro vvalue();
gsubmit '
dm "wcopy";
filename clip clipbrd;
data _null_;
infile clip;
input;
call symputx("var", _INFILE_);
run;
filename clip clear;
proc sql noprint;
select distinct &var into :varlst separated by "@"
from &syslast
;
quit;
data _null_;
if ^symexist("increment") then call symputx("increment", 1, "g");
else call symputx("increment", 1 + input(symget("increment"), best.), "g");
run;
filename clip clipbrd;
data _null_;
file clip;
length value $32767;
if &increment <= countw("&varlst", "@") then value=scan("&varlst", &increment, "@");
else value=scan("&varlst", countw("&varlst", "@"), "@");
put value;
run;
filename clip clear;';
%mend vvalue;
接下来说下设置和用法。设置如下:
keydef 'F9' '%markdsn'
keydef 'F10' '%markcode'
keydef 'F11' '%vvalue'
用法如下: