Help using Base SAS procedures

if statement

Reply
Occasional Contributor
Posts: 5

if statement


%let k=6;
%let l=5;
%let m=1;

%test(nb=5);

%macro cccc;

 

%do %until(min>=0.7);

if pe<0.7 & ps>=0.7 then

do; %let l=%eval(&l-1); %let m=&m; end;

 

if ps<0.7 & pe>=0.7 then

do; %let m=%eval(&m+1);%let l=&l; end;

 

if pe<0.7 & pe<0.7 then do; 
%let l=%eval(&l-1);
%let m=%eval(&m+1); end;

 

%test(nb=5);

%end;


med[1,1]=%eval(&l+1);
msd[1,1]=%eval(&m-1);
print med msd; print &l &m;

%mend;
%cccc;

 

Hello,

I have the problem of ignoring conditional execution and executing all three cases.
what should i do?

Occasional Contributor
Posts: 8

Re: if statement

Hello,

 

Should you use macro statements i.e. with % sign:

%if %then %do %end

...?

Super User
Posts: 10,239

Re: if statement

You obviously have no clue what the macro facility is meant for.

See this:

%do %until(min>=0.7);
if pe<0.7 & ps>=0.7 then
do; %let l=%eval(&l-1); %let m=&m; end;

Using macro statements this way can NEVER work. The %let statements are dealt with when the code for the data or proc step is fetched and compiled, so trying to execute them conditionally is nonsense.

 

And a condition like that:

%do %until(min>=0.7);

can also never work, as the macro facility will compare the text "min" with the text "0.7", so min>=0.7 is always true.

 

What are you trying to do?

 

Post your whole code, as what you have posted is missing lots of important items (like the procedure around the macro):


@shkim wrote:


%let k=6;
%let l=5;
%let m=1;

%test(nb=5);

%macro cccc;

 

%do %until(min>=0.7);

if pe<0.7 & ps>=0.7 then

do; %let l=%eval(&l-1); %let m=&m; end;

 

if ps<0.7 & pe>=0.7 then

do; %let m=%eval(&m+1);%let l=&l; end;

 

if pe<0.7 & pe<0.7 then do; 
%let l=%eval(&l-1);
%let m=%eval(&m+1); end;

 

%test(nb=5);

%end;


med[1,1]=%eval(&l+1);
msd[1,1]=%eval(&m-1);
print med msd; print &l &m;

%mend;
%cccc;

 

Hello,

I have the problem of ignoring conditional execution and executing all three cases.
what should i do?


 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 5

Re: if statement

[ Edited ]
Posted in reply to KurtBremser

ex data)

proc iml;
ze_0={1,2,3};
zs_0{1,3,5};
ze_1={2,3,4};
zs_1={2,4,2};
ze_2={1,3,2};
zs_2={2,5,4};
quit;

 

pe=#{max(ze_i[&l,1],zs_i[&m,1])>=ze_0[&l,1]}/nb
ps=#{max(zs_i[&l,1],zs_i[&m,1])>=zs_0[&m,1]}/nb

i=1,2
nb=2


I have already complete macro program code that computes pe and ps. (%test)
but, i don't know how to code this part.

 

Initial value l=3 , m=1

if pe < 0.05 then I = l-1, If ps < 0.05 then m = m + 1,

and pe and ps must be repeated until both are greater than 0.05.

Ask a Question
Discussion stats
  • 3 replies
  • 141 views
  • 2 likes
  • 3 in conversation