Hello,
I have a program with a %let pop=ITT (to choose ITT analysis population) in the beginning. Within the program I have code that has the condition if &pop.="Y" . How can I code this so that I can run the entire program for ITT and then for PP population?
Thanks in advance for any ideas.
Without seeing your program, its nearly impossible to advise.
Is ITT the name of a variable, or is it the value of a variable?
Run;
This repeats a few times in the program bringing in and merging different datasets where the condition &pop.=“Y” is used. There are also some macros within the code. With a summary table at the end.
I Want to produce the same summary table
For the different analysis populations.
I hope this clarifies the issue a bit
I feel uneasy recommending code after seeing an obviously contrived program. However, this is the outline of what you would do.
%macro do_this(pop);
data a;
set b(where=(&pop="Y"));
...
run;
/* the rest of your code goes here */
%mend;
%do_this(ITT)
%do_this(PP)
Thanks Paige,
I understand the hesitation. The program is pretty convoluted with macros embedded inside. I actually figured out how to get the macro for the populations to work - I added two ampersands i.e. if &&pop.="Y"; to each place within the program. This seems to work well now. I am not completely sure why or how this works - but will figure that out. Thanks for your input.
Double-ampersands are not necesssary here, unless there are things going on in your code that you haven't mentioned.
Hi @PaigeMiller I agree with you that double ampersand is not needed here, please see details in my other threads, one ampersand can resolve the macro. However, I am curious about how @nsns use double ampersand to resolve the macro (which obviously resolved twice) and what does the macro look like 😀
I would be happy to discuss these macro questions in their own thread. I will not discuss them in this thread, as they have deviated far from the topic of "Running a program for different populations"
It's okay, @PaigeMiller , you are welcome!
I don't know what is okay, that isn't clear. However, it is not okay, in my opinion, to ask questions about how to use macro variables in this thread, they belong in their own thread, and people (including me) will be happy to help.
Hi Paige, thanks very much for your comments and suggestions! I will pay attention later on!
Hi, so you solved the problem yourself through adding one more ampersand & before the macro &pop.? And then it is resolved to a value like 'ITT' and 'PP', isn't it 😀 , so this macro need to be resolved twice (i.e., double ampersand && should be applied) into the correct value, and the macro you are using is a big complex nested macro which I cannot imagine what does it look like 😀
Hi nsns, thank you for telling me what 'PP' stands for (I don't know what is per protocol analysis population though😀 ), I create a dataset like this and a macro according to what you described, hope this explain part of your problem. Please let me know if it does not solve your question😀.
/*create dataset*/
data weight;
input subjid weight itt $ pp $;
datalines;
101 50 y y
102 55 y y
103 58 y y
104 60 n y
105 66 n y
106 67 y n
107 68 y n
108 70 y n
109 71 y y
110 72 y y
111 80 n y
112 49 y n
112 48 y n
114 49 y y
115 45 y y
;
run;
proc print data=weight;
run;
/*create %let macro to print
dataset for different population*/
%let flag=y;
data weight_itt;
set weight;
if itt="&flag";
run;
proc print data=weight_itt;
run;
data weight_pp;
set weight;
if pp="&flag";
run;
proc print data=weight_pp;
run;
/*another way to create this macro*/
%macro popset(table,var);
%local table var;
data &table._&var;
set &table;
if &var='y';
run;
%mend popset;
%popset(weight,itt);
%popset(weight,pp);
@nsns I have another question for you: why there is a period (or dot) behind your macro variable &pop (,please see the picture, I marked it out with a red circle)?
@PaigeMiller , I am not sure whether the %local statement in my second macro write correctly, could you help confirm it? Thanks!
@dxiao2017 wrote:
@nsns I have another question for you: why there is a period (or dot) behind your macro variable &pop (,please see the picture, I marked it out with a red circle)?
@PaigeMiller , I am not sure whether the %local statement in my second macro write correctly, could you help confirm it? Thanks!
Please start a new thread with these questions, as they are not really on topic in this thread.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.