I wrote SAS program and facing some difficulty, SAS code is given below
Code description
The objective of this SAS program is to obtain correct value of variable count in each iteration of macro final.
In macro final there are some macro like %macro Boot_Perzentil1, %boot1, %boot_reml1, %boot_grenze1, together all these macros produce a single variable y and that value of y should be checked either < or > 2.49482 under the macro of %Boot_Perzentil1.
I got all macros write but code below is not working correctly, every time I run this program get count is 0 even y < 2.49482
%if y < 2.49482 %then %do;
%let count=% eval(&count+1);
%Put count is &count;
%end;
%else %do;
%let count=&count;
%Put count is &count;
%end
Plz help me
Complete SAS Code
%macro final(sim);
%let count=0;
%do rep= 1 %to 2;
%let D=&simdata&rep;
%macro Boot_Perzentil1(data,pat,b_reps);
%do b_rep=1 %to &b_reps;
%put Boot &b_rep;
%boot1(&data,btest_1,9);
%boot_reml1(btest_1,outin_1,9,logAUC,logCmax,1);
%end;
%boot_grenze1(outin_1,&b_reps);
run;
%if y < 2.49482 %then %do;
%let count=%eval(&count+1);
%Put count is &count;
%end;
%else %do;
%let count=&count;
%Put count is &count;
%end;
%mend;
%Boot_Perzentil1(&D,9,1);
%end;
%mend;
%final(want);
%if y < 2.49482 %then
This condition will always be false, as the character "y" comes later in the character sequence than the character "2".
Keep in mind that the macro processor has only "character" as data type, and that it runs before any data step variables come into existence.
PS I see no other reference to "y" outside of the %if statement. What should "y" be?
Y is the variable that is generated in the result of macro %boot_grenze1(outin_1,&b_reps);
Please guide how could I write correctly this line
%if y < 2.49482 %then
The y variable is numeric
No, it is not a variable, it is the character string "y".
IF you created a macro variable earlier with %let, then you must reference it as &y.
%let y=1;
%macro test1;
%if y < 2 %then %put "This is fun"; %else %put "not funny";
%mend;
%test1;
%macro test2;
%if &y < 2 %then %put "This is fun"; %else %put "not funny";
%mend;
%test2;
How did you create y?
In default , SAS will put %eval() around it , for your question ,you need to put %sysevalf() around it to let SAS know it float not integer .
%let y=2;
%macro test;
%if %sysevalf(&y < 2.49482) %then %put "This is fun";
%else %put "not funny";
%if &y < 2 %then %put "This is fun";
%else %put "not funny";
%mend;
%test
57
58 %let y=2;
59 %macro test;
60 %if %sysevalf(&y < 2.49482) %then %put "This is fun";
61 %else %put "not funny";
62 %if &y < 2 %then %put "This is fun";
63 %else %put "not funny";
64 %mend;
65 %test
"This is fun"
"not funny"
66
67
68 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
80
Xia Keshan
If y is a macro variable, you have to refer to it as &y. Since you are comparing decimal fractions, you need a function that allows macro language to work with decimal fractions as numbers:
%if %sysevalf (&y < 2.48492) %then %do;
Good luck.
Thanks a lot
Assuming Y is a macro variable then you probably want to use %SYSEVALF() to compare it to a non-integer value.
Formatting your code will also help. Note that you should NOT embed macro definitions inside of other macro definitions. That just does not make any sense and will make reading and maintaining the code harder.
%macro Boot_Perzentil1(data,pat,b_reps);
%do b_rep=1 %to &b_reps;
%put Boot &b_rep;
%boot1(&data,btest_1,9);
%boot_reml1(btest_1,outin_1,9,logAUC,logCmax,1);
%end;
%boot_grenze1(outin_1,&b_reps);
/* You should not need a RUN statement here. Check the definition of BOOT_GRENZEL macro to make sure that
it is properly terminating any data or proc steps that it generates
*/
%if %sysevalf(&y < 2.49482) %then %do;
%let count=%eval(&count+1);
%Put count is &count;
%end;
%else %do;
%let count=&count;
%Put count is &count;
%end;
%mend;
%macro final(sim);
%let count=0;
%do rep= 1 %to 2;
%let D=&simdata&rep;
%Boot_Perzentil1(&D,9,1);
%end;
%mend;
Thank you very much I did the same and got the desired resutls
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.