BookmarkSubscribeRSS Feed
animesh123
Obsidian | Level 7
If Cp1=psg and psg-seg= land and cp2 ="" then rank=2 else rank=1
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

This is Data Step Syntax. The Data Step does not have a Case Statement. Instead, I think you want to write a Select Statement and do something like

 

select;
   when (Cp1 = psg and psg-seg = land and cp2 = "") rank = 2;
   otherwise rank = 1;
end;
PaigeMiller
Diamond | Level 26

@animesh123 wrote:
If Cp1=psg and psg-seg= land and cp2 ="" then rank=2 else rank=1

Replace IF with CASE WHEN, clean up the syntax after THEN

 

case when Cp1=psg and psg-seg= land and cp2 ="" then 2 else 1 end as rank

As pointed out by @PeterClemmensen you can't use this in a DATA step, only in PROC SQL

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 600 views
  • 1 like
  • 3 in conversation