BookmarkSubscribeRSS Feed
kajal_30
Quartz | Level 8

Hi Channel,

 

I have "IF else" statement which I want to convert to "case when" could you please help .

 

IF Rate "" THEN DO ;
  A ="LIGHT"; B =1;
  IF HIGH =1 THEN DO;
   U = A1 ;
   V = 1;
   W = 1;
   X = A1_PO;
   Y = 1;
   Z = 1;
  END;
  IF HIGH =2 THEN DO;
   U = 1;
   V = A1 ;
   W = 1;
   X = 1;
   Y = A1_PO;
   Z = 1;
  END;
  IF HIGH =3 THEN DO;
   U = 1;
   V = 1;
   W = A1 ;
   X = 1;
   Y = 1;
   Z = A1_PO;
  END;
  
 END;
 ELSE IF AMOUNT 1  NE AMOUNT 2 THEN DO;
  A ="HARD"; B =2;
  IF HIGH =1 THEN DO;
   U = APPLE;
   V = 1;
   W = 1;
   X = APPLE_GREEN;
   Y = 1;
   Z = 1;
  END;
  IF HIGH =2 THEN DO;
   U = 1;
   V = APPLE;
   W = 1;
   X = 1;
   Y = APPLE_GREEN;
   Z = 1;
  END;
  IF HIGH =3 THEN DO;
   U = 1;
   V = 1;
   W = APPLE;
   X = 1;
   Y = 1;
   Z = APPLE_GREEN;
  END;
  END;
 ELSE DO ;
  A = "SOFT" ; B =3;
  IF HIGH =1 THEN DO;
   U = ORANGE;
   V = 1;
   W = 1;
   X = ORANGE_TANGY;
   Y = 1;
   Z = 1;
  END;
  IF HIGH =2 THEN DO;
   U = 1;
   V = ORANGE;
   W = 1;
   X = 1;
   Y = ORANGE_TANGY;
   Z = 1;
  END;
  IF HIGH =3 THEN DO;
   U = 1;
   V = 1;
   W = ORANGE;
   X = 1;
   Y = 1;
   Z = ORANGE_TANGY;
  END;
 
END;

 

I have converted all but can't able fit all under ELSE.

Please help and I want to use sql "case when" because I want to migrate this to angular SQL so can't use data step

2 REPLIES 2
Tom
Super User Tom
Super User

In SQL you will need to redo the logic so that it calculates each output variable independently.  You appear at first glance to have output variables of A,B,U, V, W, X, Y and Z so you will need 8 CASE .... END clause in your SQL select statement.

PGStats
Opal | Level 21

Show us the case-when expression you have for, say, U.

PG

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 496 views
  • 0 likes
  • 3 in conversation