BookmarkSubscribeRSS Feed
dxiao2017
Lapis Lazuli | Level 10
Thanks for the suggestion Paige! I did not use %local statement in a macro before and do not know whether I use it correctly, in this post I think you can help with my question so I referred to you in this thread. Sorry for it if it looks irrelevant!
nsns
Quartz | Level 8
I use a dot when I refer to a macro variable.
dxiao2017
Lapis Lazuli | Level 10

You do not always need a period (a dot) to resolve a macro, except the macro value only constitutes part of your string then you need a dot to separate the two parts. For examples (I typed code here and run the code in windowing environment 9.4 base, btw😀 and this does not make any difference just somehow want to mention it btw😀)

%let var=employee;
%put Employees resolves to &var.s as it is.;

%let lib=weight;
%let table=itt;
%put The dataset weight.itt resolves to &lib..&table as it is.;

 

Capture1.JPG

 

dxiao2017
Lapis Lazuli | Level 10

Please discard my first %let macro in my last thread (the way I create that %let macro was odd and funny, I don't know what's wrong with my mind then 😀). Here is the right one (and you do not need to use one more ampersand to resolve the macro):

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 pop=itt;
data weight_&pop;
   set weight;
   if &pop="y";
run;
proc print data=weight_&pop;
run;
%let pop=pp;
data weight_&pop;
   set weight;
   if &pop="y";
run;
proc print data=weight_&pop;
run;

dxiao2017_0-1744915376221.png

dxiao2017_2-1744915443648.png

dxiao2017_3-1744915507991.png

dxiao2017
Lapis Lazuli | Level 10

And also I forgot to write the proc print step in the second macro in my previous thread, here is the correction:

%macro popset(table,var);
%local table var;
data &table._&var;
   set &table;
   if &var='y';
run;
proc print data=&table._&var;
run;
%mend popset;
%popset(weight,itt);
%popset(weight,pp);
dxiao2017
Lapis Lazuli | Level 10

'ITT' stands for 'Intend To Treat' population. I forget what 'PP' stands for. I read the terms in some materials about clinical trial dataset before. 'ITT' should be the column name if I remember it right, and has value of "Y" (which flags this subject belongs to ITT population) and "N" (which flags this subject does not belong to ITT population). Mean statistics is calculated base on different populations, sometimes you need to report statistics for all samples(or subjects, participants), other times you need statistics for the ITT population only.

nsns
Quartz | Level 8

PP stands for Per-Protocol analysis population. 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 1856 views
  • 8 likes
  • 3 in conversation