Hello,
I'm trying the below, which isn't the correct syntax
if Funded_Trips =6 or Funded_Trips =4 then
if TripsCompleted < IMTarget or if TripsCompleted < Target then TargetMet= 'N'
else 'Y' ;
I was hoping someone could give me the correct snytax.
Cheers
Haydn
if Funded_Trips in (4, 6)
and (TripsCompleted < IMTarget or TripsCompleted < Target ) then TargetMet= 'N';
else TargetMet='Y' ;
Here's a possibility:
if (Funded_Trips =6 or Funded_Trips =4) and (TripsCompleted < IMTarget or TripsCompleted < Target) then TargetMet= 'N';
else TargetMet='Y' ;
But the right answer depends on when the ELSE condition should kick in.
if Funded_Trips in (4, 6)
and (TripsCompleted < IMTarget or TripsCompleted < Target ) then TargetMet= 'N';
else TargetMet='Y' ;
Hi:
I suggest you activate the free Programming 1 course and review the DATA step language for conditional processing and how IF statements work.
Without data, it is hard to know what you want to do, my tendency is to use AND and then use parentheses to group the OR conditions like this:
if (Funded_Trips =6 or Funded_Trips =4) and
(TripsCompleted < IMTarget or TripsCompleted < Target) then TargetMet= 'N';
else TargetMet='Y' ;
on the other hand, you could want:
if (Funded_Trips =6 or Funded_Trips =4) then do;
if (TripsCompleted < IMTarget or TripsCompleted < Target) then do;
TargetMet= 'N';
end;
end;
else TargetMet='Y' ; /* any other value for Funded_Trips gets TargetMet = Y */
but, as I said, without data, and seeing what you have and what you want, it is hard to speculate. The above codes might or might not generate the desired results.
cynthia
Binary choices can be simplified with ifn/ifc functions:
targetmet=ifc(funded_trips in (4,6) and tripscompleted < max(imtarget,target),'N','Y');
@RW9 consider default length. You would probably want to define the length of "TARGETMET" and not let it default.
25 data _null_;
26 x = ifc(1,'Y','N');
27 lx = vlength(x);
28 put _all_;
29 run;
x=Y lx=200 _ERROR_=0 _N_=1
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.