BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Haydn
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
   if Funded_Trips in (4, 6) 
      and (TripsCompleted < IMTarget or  TripsCompleted < Target ) then TargetMet= 'N';
  else TargetMet='Y' ;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.  

Reeza
Super User
   if Funded_Trips in (4, 6) 
      and (TripsCompleted < IMTarget or  TripsCompleted < Target ) then TargetMet= 'N';
  else TargetMet='Y' ;
Cynthia_sas
SAS Super FREQ

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Binary choices can be simplified with ifn/ifc functions:

targetmet=ifc(funded_trips in (4,6) and tripscompleted < max(imtarget,target),'N','Y');
data_null__
Jade | Level 19

@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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1273 views
  • 2 likes
  • 6 in conversation