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

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

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
  • 870 views
  • 1 like
  • 3 in conversation