Help using Base SAS procedures

Counts in if/then/else statements

Reply
N/A
Posts: 0

Counts in if/then/else statements

I have an if then else statement (shown below) that does not seem to pull all the numbers in. Is there a problem with the Counts? Is there another way to write a statement like this?

if Retention_EndStatus ne 'CLOSED' then EndStatus = 'SAVED ';
else EndStatus = 'CLOSED';
if EndStatus eq 'SAVED ' then SavCnt = 1; else
if EndStatus eq 'CLOSED' then CloCnt = 1;
if EndStatus eq 'SAVED ' then do;
if retention_fulfill ne ' ' then Offer = retention_fulfill;
else Offer = retention_fulfilloo;
Super Contributor
Posts: 359

Re: Counts in if/then/else statements

To start with you are testing the same thing several times. Also do you have default values for the things you are not setting in each condition?


if Retention_EndStatus ne 'CLOSED' then Do;
EndStatus = 'SAVED ';
SavCnt = 1;
*** What happens to CloCnt ??? ;
if retention_fulfill ne ' ' then Offer = retention_fulfill;
else Offer = retention_fulfilloo;
end;

else Do;
CloCnt = 1;
** What happens to SavCnt ???;
EndStatus = 'CLOSED';
** What happens to Offer ???;
end;
PROC Star
Posts: 1,564

Re: Counts in if/then/else statements

One of many ways to write the same tests:
[pre]
if Retention_EndStatus ne 'CLOSED' then do;
EndStatus = 'SAVED ';
SavCnt = 1;
Offer = ifc( retention_fulfill ne ' ', retention_fulfill, retention_fulfilloo);
end;
else do;
EndStatus = 'CLOSED';
CloCnt = 1;
end;
Ask a Question
Discussion stats
  • 2 replies
  • 99 views
  • 0 likes
  • 3 in conversation