(Note: the original post was edited since I tried a new approach)
This is an interim analysis example. There are 4 look points, and the user can define the portion of alpha that they want to 'spend' at each look point. Data are entered cumulatively.
Right now, I have each of the alpha_looks stored as separate macro variables using symputx.
When alpha_spend=3 (meaning the user wants to enter their own alpha values instead of relying on what's generated through code), the main macro will pull these values in. I'm having some trouble with the last step, and I've made comments to highlight where the problem is.
Thanks for taking a look! I've used a lot of the community input to make changes to this code.
data UserDefAlpha; /*input alpha_look=3 in main macro to use user-defined alpha values*/
input numuser @;
call symputx("numuser",numuser,'G');
do i=1 to &numuser;
input alpha_look @;
output;
end;
/*first value of datalines must be num_look(the number of looks)*/
datalines;
4 0.011 0.015 0.02 0.025
;
run;
data UserDefAlpha2;
set UserDefAlpha;
do j=1 to &numuser;
if j=i then
call symputx(catt('alpha_look',j),alpha_look,'G');
end;
run;
%put alpha_look1 = &alpha_look1;
%put alpha_look2 = &alpha_look2;
%put alpha_look3 = &alpha_look3;
%put alpha_look4 = &alpha_look4;
%macro example(alpha_spend=);
data example;
array alpha_look[&numuser] alpha_look1 - alpha_look&numuser;
if &alpha_spend = 3 then
do j=1 to &numuser;
*alpha_look[j] = &&alpha_look&j ; /*the &j portion on the right hand side of the equation does not work*/
alpha_look[j] = &&alpha_look1 ; /*this line of code works, but I want to dynamically reference the stored macro variables, instead of just alpha_look1*/
end;
run;
proc print; run;
%mend;
%example(alpha_spend=3);
Original code for reference:
%macro example(alpha_spend=);
proc transpose data=UserDefAlpha prefix=alpha_look out=UserDefAlpha; /*transpose the userinput dataset*/
run;
data UserDefAlpha( drop= _NAME_); /*keep only alpha_looks*/
set UserDefAlpha;
if _NAME_~='Alpha_Look' then delete;
run;
data example (keep= Alpha_Look);
if &alpha_spend = 1 then
do;
Alpha_Look = 0.05/2;
end;
*if &alpha_spend = 2 then I want the user-input value, 0.05, pulled from the dataset UserDefAlpha;
run;
proc print; run;
%mend;
data UserDefAlpha;
input numuser @;
do i=1 to &numuser;
input Alpha_Look @;
output;
end;
datalines;
1 0.05
;
run;
%example(alpha_spend=2);
How do you go from alpha_spend=2 to the fact that you want 0.05? What is the logic? What is in data set UserDefAlpha?
There's no meaning behind this dataset. This is just an example.
Users can input an alpha and the proportion of alpha they want to spend at each time point.
For this dataset, there's only one time value, and all of alpha is spent on it.
@thewan wrote:
There's no meaning behind this dataset. This is just an example.
But yet you go through the trouble of transposing it ... this is confusing, why would you do that if there is no meaning behind this dataset?
Users can input an alpha and the proportion of alpha they want to spend at each time point.
For this dataset, there's only one time value, and all of alpha is spent on it.
I'm sorry, but I am no closer to understanding what you are trying to do, and how an input of 2 results in the desired output of 0.05.
I was trying to simplify the original problem to be posted on the community forum. Maybe I should have said this better. By saying the dataset has no meaning, I meant the values aren't realistic, that's all.
I'd still like to leave this up in case anyone has input. I've found the suggested solutions to be helpful.
Can you give an example of "UserDefAlpha" please? Your data step doesn't produce any observation
Thanks,
It is not at all clear what you are trying to do but it looks like you have over complicated the process.
It sounds like you just want to test the macro parameters value and then make a decision about which value to use. The value from the dataset provided by the user or some default value, like 0.05.
For example this macro will read in the dataset USERDEFDATA and make a new dataset named ALPHA_LOOK that has just the variable ALPHA_LOOK. If ALPHA_SPEND is set to 1 in the macro call then the variable will always be 0.025. Otherwise it will keep whatever value it already had.
%macro example(alpha_spend=);
data alpha_look ;
set UserDefData (keep=alpha_look);
%if &alpha_spend = 1 %then %do;
alpha_look=0.05/2 ;
%end;
keep alpha_look;
run;
%mend example;
If you situation is more complex then you need to explain in more detail,with example input and output data.
JeanDo and Tom, thanks for taking a look at the problem. I've been working on this and came up with another approach that uses symputx to store the macro variables.
This is an interim analysis example. There are 4 look points, and the user can define the portion of alpha that they want to 'spend' at each look point. Data are entered cumulatively.
Right now, I have each of the alpha_looks stored as separate macro variables using symputx.
When alpha_spend=3 (meaning the user wants to enter their own alpha values instead of relying on what's generated through code), the main macro will pull these values in. I'm having some trouble with the last step, and I've made comments to highlight where the problem is.
Thanks for taking a look! I've used a lot of the community input to make changes to this code.
data UserDefAlpha; /*input alpha_look=3 in main macro to use user-defined alpha values*/
input numuser @;
call symputx("numuser",numuser,'G');
do i=1 to &numuser;
input alpha_look @;
output;
end;
/*first value of datalines must be num_look(the number of looks)*/
datalines;
4 0.011 0.015 0.02 0.025
;
run;
data UserDefAlpha2;
set UserDefAlpha;
do j=1 to &numuser;
if j=i then
call symputx(catt('alpha_look',j),alpha_look,'G');
end;
run;
%put alpha_look1 = &alpha_look1;
%put alpha_look2 = &alpha_look2;
%put alpha_look3 = &alpha_look3;
%put alpha_look4 = &alpha_look4;
%macro example(alpha_spend=);
data example;
array alpha_look[&numuser] alpha_look1 - alpha_look&numuser;
if &alpha_spend = 3 then
do j=1 to &numuser;
alpha_look[j] = &&alpha_look&j ; /*the &j portion on the right hand side of the equation does not work*/
*alpha_look[j] = &&alpha_look1 ; /*this line of code works, but I want to dynamically reference the stored macro variables, instead of just alpha_look1*/
end;
run;
proc print; run;
%mend;
%example(alpha_spend=3);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: