- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Without seeing your program, its nearly impossible to advise.
Is ITT the name of a variable, or is it the value of a variable?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
By groups wouldn’t work because of the structure of the datasets. There are variables to identify which observations (ie subjects) belong to which populations. Ie ITT=Y/N, PP=Y/N.
The code is basically
%let pop= ITT
data a;
Set b;
If &pop.=“Y”;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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)
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Double-ampersands are not necesssary here, unless there are things going on in your code that you haven't mentioned.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 😀
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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"
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It's okay, @PaigeMiller , you are welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Paige, thanks very much for your comments and suggestions! I will pay attention later on!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 😀
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
Paige Miller