BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

I have a question in this macro which I am using. The macro gives me output I need. But my question is about "%put &b1 &c1 &d1  &f1;" statement in the macro.

 

when I put "%put &b1 &c1 &d1  &f1;"  statement in the macro it shows numerical numbers in the log which exactly the I am expecting

But when I use this  "%put &var6 &var7 &var8  &var9; "  statement it shows 'b1'  'c1' 'd1' 'f1' in the log.

 

Please suggest how should I get the output in the logI got when i used  "%put &b1 &c1 &d1  &f1;" statement IN THE MACRO. 

I am planning to use "%put &var6 &var7 &var8  &var9; statement instead of "%put &b1 &c1 &d1  &f1;" statement as the values change for my next table

Thank you very much.

 

%macro three(var1=,var2=,var3=,var4=,var5=,var6=,var7=,var8=,var9=); 

data &var1(keep=usubjid trt01a);
length TRT01A $50.;
set adsl;
if &var2;
if trt01a in ('JZP-110 75mg' 'JZP-110 150mg' 'JZP-110 300mg');
format trt01a $trta.;
run;

proc sql;
create table &var3 as
select count(distinct usubjid) as NS,TRT01A
from &var1
group by TRT01A;
quit; 

data &var4;
set &var3;
trt01a=strip(trt01a);
if trt01a='JZP-110 75mg' then trt=&var6;
if trt01a='JZP-110 150mg' then trt=&var7;
if trt01a='JZP-110 300mg' then trt=&var8;
run;

data &var5;
set &var4 end=done;
if trt01a in ('JZP-110 150mg', 'JZP-110 300mg', 'JZP-110 75mg' ) then Total + ns;
output;
if done;
ns = TOTAL;
trt=&var9;
trt01a='Total';
output;
drop Total;
run;

data _null_;
set &var5;
call symputx(trt,ns);
run;

%put &b1 &c1 &d1  &f1;

%put &var6 &var7 &var8 &var9;
%mend;

%three(var1=adsl1,var2=saffl="Y",var3=TNSTFD,var4=tnstfd1,var5=tnstfd11,var6='b1',var7='c1',var8='d1',var9='f1');

 

10 REPLIES 10
Tom
Super User Tom
Super User

Looking quickly at your macro it is clear that the macro variables VAR1, VAR2, etc have the names of DATASETS. So of course when you ask SAS to print the values of the macro variables it will print those data set names.

 

So what do you want it to do instead?

knveraraju91
Barite | Level 11

Thank you very much for your time. Bellow is the short explanation what I am looking. If this is not clear, I am very sorry. I will try to put my question better way next time.

 

Beofore I created the macro, I used to ran "%put &b &c &d &f;" statement at the end to check the numbers. 

 

Now I created a macro which includes same code as I will be running on different tables . My question is,  If I want to check the numbers as before  what statement should i include in the macro

 

data _null_;
set tnstfd11;
call symputx(trt,ns);
run;
%put &b &c &d &f;

ChrisNZ
Tourmaline | Level 20

Does my code yield the result that you expect when you run it?

knveraraju91
Barite | Level 11

Thank you very much. I got the output with the below statement.

%put &&&var6 &&&var7 &&&var8 &&&var9;

 

Tom
Super User Tom
Super User

Why not just print the numbers from the dataset instead of the macro variables?

 

data _null_;
  set tnstfd11;
  call symputx(trt,ns);
  put trt= ns= ;
run;

Why are you putting the numbers into macro variables anyway?  If you need them as macro variables then your probably should not be putting them into LOCAL macro variables as those will disappear when the macro finishes.

ChrisNZ
Tourmaline | Level 20

It's very difficult to guess what you are after from what you posted.

You are not helping yourself at all here by putting so little effort into this post.

 

Maybe that's what you want:


  %let b1=1;
  %let c1=1;
  %let d1=1;
  %let f1=1;
  data ADSL; retain USUBJID TRT01A SAFFL ' '; run;

%macro three(var1=,var2=,var3=,var4=,var5=,var6=,var7=,var8=,var9=); 
%macro _;%mend _;
data &var1(keep=usubjid trt01a);
  length TRT01A $50.;
  set adsl;
  if &var2;
  if trt01a in ('JZP-110 75mg' 'JZP-110 150mg' 'JZP-110 300mg');
  *format trt01a $trta.;
run;

proc sql;
  create table &var3 as
  select count(distinct usubjid) as NS,TRT01A
  from &var1
  group by TRT01A;
quit; 

data &var4;
  set &var3;
  trt01a=strip(trt01a);
  if trt01a='JZP-110 75mg'  then trt="&var6";
  if trt01a='JZP-110 150mg' then trt="&var7";
  if trt01a='JZP-110 300mg' then trt="&var8";
run;

data &var5;
  set &var4 end=done;
  if trt01a in ('JZP-110 150mg', 'JZP-110 300mg', 'JZP-110 75mg' ) then Total + ns;
  output;
  if done;
  ns = TOTAL;
  trt="&var9";
  trt01a='Total';
  output;
  drop Total;
  call symputx(trt,ns);
run;

%put 1- &b1 &c1 &d1 &f1;

%put 2- &&&var6 &&&var7 &&&var8 &&&var9;
%mend; 

%three(var1=adsl1,var2=saffl="Y",var3=TNSTFD,var4=tnstfd1,var5=tnstfd11
,var6=b1,var7=c1,var8=d1,var9=f1);
 

1- 1 1 1 1
2- 1 1 1 1

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, what is it your actually trying to do as to me this code doesn't do anything?  Post example test data in a datastep and what you want out.  A simple datastep should be able to list out the treatments??

Kurt_Bremser
Super User

var6 to var9 contain the macro variable names you want to use in thge data _null_ step. Since you never reset those variables, their content will stay as it is. If you want to display the content of a macro variable that is referenced by another macro variable, use a double ampersand.

To facilitate that, get rid of the quotes:

%three(var1=adsl1,var2=saffl="Y",var3=TNSTFD,var4=tnstfd1,var5=tnstfd11,var6=b1,var7=c1,var8=d1,var9=f1);

Next, change the way you use those macrovars:

data &var4;
set &var3;
trt01a=strip(trt01a);
if trt01a='JZP-110 75mg' then trt="&var6";
if trt01a='JZP-110 150mg' then trt="&var7";
if trt01a='JZP-110 300mg' then trt="&var8";
run;

data &var5;
set &var4 end=done;
if trt01a in ('JZP-110 150mg', 'JZP-110 300mg', 'JZP-110 75mg' ) then Total + ns;
output;
if done;
ns = TOTAL;
trt="&var9";
trt01a='Total';
output;
drop Total;
run;

Now you can use

%put &&var6 &&var7 &&var8 &&var9;
knveraraju91
Barite | Level 11

Thank you all for the support. I ran the following statement  and I got what I am looking for.

%put &&&var6 &&&var7 &&&var8 &&&var9;

 

ChrisNZ
Tourmaline | Level 20

Please mark this thread as solved then.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1160 views
  • 3 likes
  • 5 in conversation