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

I have the current sas code that works fine:

 

DATA td.data_new
set td.data;
if not missing(A) then Points = 250;
else if B >= 10 and C= 0 then Points = 230;
else if D <6 and E >60 then Points = 150;
run;

 I want to convert this to some equivalent SQL code, so that I can use it in a proc sql statement. Any help would be appreciated, thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @sasprogramming 

 

You need to mention "ELSE" only once at the end and remove commas.

proc sql;
	create table data_new as
	select a,b,c,d,e,
	case when a ne . then 250
		 when b>=10 and c=0 then 230
		 when d<6 and e>60 then 150
		 else . end as points
	from data;
quit;

 

Best,

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

please try

 

proc sql;
create table td.data_new as select a,b,c,d,e, case when a ne . then 250 else when b>=10 and c=0 then 230, else when d<6 and e>60 then 150 else . end as points from td.data;
quit;
Thanks,
Jag
sasprogramming
Quartz | Level 8

Thank you but I am receiving this error? 

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, AND, EQ, EQT,
GE, GET, GT, GTT, LE, LET, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ed_sas_member
Meteorite | Level 14

Hi @sasprogramming 

 

You need to mention "ELSE" only once at the end and remove commas.

proc sql;
	create table data_new as
	select a,b,c,d,e,
	case when a ne . then 250
		 when b>=10 and c=0 then 230
		 when d<6 and e>60 then 150
		 else . end as points
	from data;
quit;

 

Best,

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
  • 3 replies
  • 1462 views
  • 3 likes
  • 3 in conversation