/*資料筆數存成 Macro Variable*/
/*方法一*/
Proc Sql noprint;
/*Macro Variable N1 */
select Count ( Distinct subjid ) format=3.
into :N1
from treat
where trtcd = 1;
/*Macro Variable N2 */
select count(distinct subjid) format = 3.
into :n2
from treat
where trtcd = 0;
Quit;
%put &N1 &N2;
/*方法二*/
data _null_;
set treat end = eof;
**** 分組的 COUNTER 並 retain 住;
if trtcd = 1 then
n1 + 1;
else if trtcd = 0 then
n2 + 1;
**** 總 COUNTER.;
n3 + 1;
**** 資料最後一列即為所要的數值;
if eof then
do;
call symput("n1", put(n1,3.)); *用 PUT 數值轉為文字;
call symput("n2", put(n2,3.));
call symput("n3", put(n3,3.));
end;
run;
/*一組變項定義為 Macro Variables*/
/*方法一 用 Arrary*/
DATA A;
Array Vars {8} $18. (
'Dis_hypertension'
'Dis_DM'
'Dis_hyperlipidemia'
'Dis_stroke'
'dis_asthma'
'Dis_Kidney'
'Dis_HD'
'Dis_osteoporosis'
) ;
Do i =1 to 8;
Call symput ( 'I_num' , compress(i) );
Call symput ( 'Vv'||compress(i) , Vars{i} );
End;
run;
%Put &I_num;
%Put &Vv1 &Vv2 &Vv8 ;
/*方法二 用資料檔處理的方式*/
%LET Text= 那一整群變項;
/*以變項群建立新資料檔(橫向)*/
DATA M_LIST ; input &text; run;
/*讀 sashelp.Vcolumn取得資料檔訊息(直向)*/
Proc Sql;
Create Table M_LIST2 AS
Select Name as MVAR_LIST From sashelp.Vcolumn
Where libname='WORK' and memname='M_LIST' ;
Quit;
/*以及變項群數目*/
Proc Sql noprint;
Select nvar into
:Num From Sashelp.Vtable
Having libname='WORK' and memname='M_LIST' ;
Quit;
/*巨集變項名稱 Var1, Var2, ~ VarN */
DATA M_Vars (Keep= MVAR_PRE);
Pre='Var' ;
do i=1 to &Num; MVAR_PRE=Pre||compress(i); output; End;
run;
/*Macro name 與 變項群 MERGE,Symput為 Macro Variable*/
DATA _NULL_ ; Merge M_vars M_list2 ;
Call Symput ( MVAR_PRE, MVAR_LIST); run;