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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 878 views
  • 0 likes
  • 3 in conversation