📄 putdata.sas
字号:
%macro putdata(name=, dir=default, dataout= , mult= );
%if (&dataout ne and &mult eq ) %then %let mult = 1;
%let msg = ;
%let path = ;
%let setup = old;
%setup;
%if (%bquote(&msg) eq ) %then %do;
%let datain = ;
%let multiples = ;
%let keys = datain multiples;
%if (&dataout eq ) %then %let keys = &keys dataout;
%getkeys;
%if (%bquote(&datain) eq ) %then %let msg = No Datain file.;
%else %if (%bquote(&dataout) eq ) %then %let msg = No Dataout file.;
%else %do;
%if (&multiples eq ) %then %let multiples = 1;
%if (&mult eq ) %then %let mult = %scan(&dataout, 2, " ");
%let dataout = %scan(&dataout, 1, " ");
%if (&mult eq ) %then %let mult = 1;
%else %do;
%if (%length(&mult) ge 3) %then %do;
%let mult = %upcase(%substr(&mult, 1, 3));
%if (&mult eq ALL or &mult eq CON) %then %let mult = all;
%end;
%if (&mult ne all) %then %if (&mult le 0 or &mult gt &multiples) %then %let msg = Invalid multiple.;
%end;
%end;
%end;
%if (%bquote(&msg) eq ) %then %do;
%put Output data.;
%let llong = 8;
%let lshort = 2;
%let ldouble = 8;
data &dataout;
set &datain;
array _vcor_(32767) _temporary_;
retain _crecl_ _obs_;
infile "&path..cor" recfm=n;
if (_n_ eq 1) then do;
input _crecl_ ib&llong..;
if (_crecl_ gt 0) then do;
input _obs_ ib&llong..;
_crecl_ = _crecl_ - 2 * &llong;
end;
end;
%if (&mult eq all) %then %do;
if (_n_ eq _obs_) then do;
input _ncor_ ib&lshort..;
do _i_ = 1 to _ncor_;
input _vcor_(_i_) ib&lshort..;
end;
_crecl_ = _crecl_ - (_ncor_ + 1) * &lshort;
_len_ = (floor(_ncor_/4) * 4 - _ncor_ + 3) * 2;
if (_len_ gt 0) then do;
input +_len_;
_crecl_ = _crecl_ - _len_;
end;
do _mult_ = 1 to &multiples;
do _i_ = 1 to _ncor_;
_vnum_ = _vcor_(_i_);
filename imvars "&path..imv";
%include imvars;
end;
filename kpvars "&path..kpv";
%include kpvars;
output;
end;
input _crecl_ ib&llong..;
if (_crecl_ gt 0) then do;
input _obs_ ib&llong..;
_crecl_ = _crecl_ - 2 * &llong;
end;
end;
else do;
do _mult_ = 1 to &multiples;
filename kpvars "&path..kpv";
%include kpvars;
output;
end;
end;
%end;
%else %do;
%if (&multiples ne ) %then %do;
_mult_ = &mult;
%end;
if (_n_ eq _obs_) then do;
input _ncor_ ib&lshort..;
do _i_ = 1 to _ncor_;
input _vcor_(_i_) ib&lshort..;
end;
_crecl_ = _crecl_ - (_ncor_ + 1) * &lshort;
_len_ = (floor(_ncor_/4) * 4 - _ncor_ + 3) * 2;
if (_len_ gt 0) then do;
input +_len_;
_crecl_ = _crecl_ - _len_;
end;
if (&mult gt 1) then do;
_len_ = (&mult - 1) * _ncor_ * &ldouble;
_crecl_ = _crecl_ - _len_;
input +_len_;
end;
do _i_ = 1 to _ncor_;
_vnum_ = _vcor_(_i_);
filename imvars "&path..imv";
%include imvars;
end;
_crecl_ = _crecl_ - _ncor_ * &ldouble;
if (_crecl_ gt 0) then input +_crecl_;
input _crecl_ ib&llong..;
if (_crecl_ gt 0) then do;
input _obs_ ib&llong..;
_crecl_ = _crecl_ - 2 * &llong;
end;
end;
filename kpvars "&path..kpv";
%include kpvars;
%end;
run;
%end;
%if (%bquote(&msg) ne ) %then %put &msg;
%mend putdata;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -