s********e 发帖数: 255 | 1 Dear all,
I’m having a problem writing a SAS macro.
Briefly, I would like to store values of a variable from a dataset to a
macro variable, and use those values in the regression model.
For example, the B variable in the following model is a continuous model and
I would like to update the &I in the following model with a series of
values of B, such as 2, 6, 9, 13, etc, one for each time.
PROC RLOGIST DATA=FINAL FILETYPE=SAS;
NEST SDMVSTRA SDMVPSU;
WEIGHT WTDR2D4YR;
CLASS A;
MODEL Y= A B A*B;
PREDMARG A*B / B=(&I);
PRED_EFF B=(-1 1)*A=(1) / A=(&I);
RUN;
So I tried the following way by using CALL SYMPUT. However, it turned out to
be that only the last observation (value) of B will be used, rather than
using the values one by one. Could someone please help me out? Thank you
very much.
DATA _NULL_;
CALL SYMPUT (“I”, B);
PROC RLOGIST DATA=FINAL FILETYPE=SAS;
NEST SDMVSTRA SDMVPSU;
WEIGHT WTDR2D4YR;
CLASS A;
MODEL Y= A B A*B;
PREDMARG A*B / B=(&I);
PRED_EFF B=(-1 1)*A=(1) / A=(&I);
RUN;
RUN; |
Z****B 发帖数: 195 | 2 那个symput 中 I 只有一个值 , 去掉引号试试。 不行就 loop 一下吧 |
s********e 发帖数: 255 | 3 Thank you for the reply. Please bear with me; I cannot type in Chinese here.
I did try a loop, which was like:
DATA _NULL_;
DO j = 1 TO 5;
CALL SYMPUT (“I”, B);
PROC RLOGIST DATA=FINAL FILETYPE=SAS;
NEST SDMVSTRA SDMVPSU;
WEIGHT WTDR2D4YR;
CLASS A;
MODEL Y= A B A*B;
PREDMARG A*B / B=(&I);
PRED_EFF B=(-1 1)*A=(1) / A=(&I);
RUN;
END;
RUN;
But it didn't work, either.
【在 Z****B 的大作中提到】 : 那个symput 中 I 只有一个值 , 去掉引号试试。 不行就 loop 一下吧
|
s********e 发帖数: 255 | 4 Which 引号 do you mean?
【在 Z****B 的大作中提到】 : 那个symput 中 I 只有一个值 , 去掉引号试试。 不行就 loop 一下吧
|
Z****B 发帖数: 195 | 5 You should deal with it in the symput if you do loop |
Z****B 发帖数: 195 | 6 I 的引号
【在 s********e 的大作中提到】 : Which 引号 do you mean?
|
s********e 发帖数: 255 | 7 Sorry, I don't quite get you. Would you mind writing the code down for me?
Thank you very much.
【在 Z****B 的大作中提到】 : You should deal with it in the symput if you do loop
|
Z****B 发帖数: 195 | 8 How about this one if you need run 5 times:
%macro log(I)
PROC RLOGIST DATA=FINAL FILETYPE=SAS;
NEST SDMVSTRA SDMVPSU;
WEIGHT WTDR2D4YR;
CLASS A;
MODEL Y= A B A*B;
PREDMARG A*B / B=(&I);
PRED_EFF B=(-1 1)*A=(1) / A=(&I);
RUN;
%mend;
%log(value1)
%log(value2)
and so on. |
s******8 发帖数: 102 | 9 %macro for_u;
proc sql;
select distinct b into: allb separated by ' '
from final;
%let nb=&sqlobs;
quit;
%do j=1 %to &nb;
%let I=%scan(&allb,&j);
PROC RLOGIST DATA=FINAL FILETYPE=SAS;
NEST SDMVSTRA SDMVPSU;
WEIGHT WTDR2D4YR;
CLASS A;
MODEL Y= A B A*B;
PREDMARG A*B / B=(&I);
PRED_EFF B=(-1 1)*A=(1) / A=(&I);
RUN;
%end;
%mend
%for_u; |