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

Hi , i'm trying to do update with cases but sas don't allow me. The 'Case' isn't active. It's not blue but gray and doesn't work. I'm just learnig, can someone tell me what might be the problem?

proc sql;

update anacars.rabat

set (roznica=

case                                                       <------------------------------------------

when roznica <1000 then 'Rank1'

select * from anacars.rabat;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

roznica<1000 indicates that roznica field would be numeric to be, but then you reassign it a value of 'Rank1' which is character.

As long as you realize that 200>1000 in character language I guess the following is what you want in terms of programming. Logically it doesn't make sense to me.

You have an additional bracket, are missing the end and are also missing the semicolon at the end. In terms of the IDE, I don't believe that the case and other key words are coloured when using it in an update statement, but it still works.

proc sql;

update anacars.rabat

set roznica=

case                                                       <------------------------------------------

when roznica <'1000' then 'Rank1' end;

select * from anacars.rabat;

View solution in original post

5 REPLIES 5
stat_sas
Ammonite | Level 13

Hi,

Create a new variable rank in your existing data set anacars.rabat then update the same based on roznica variable in proc sql;

Thanks,

data anacars.rabat;
set anacars.rabat;
length rank $ 10.;
run;

proc sql;
update anacars.rabat
set rank=(case when roznica <1000 then 'Rank1' end);
quit;

Peter_C
Rhodochrosite | Level 12

pwrhaps you only need to move the open (

update anacars.rabat

set roznica= ( select something

Reeza
Super User

You need a new variable because your old variable looks to be numeric and you want a character variable. If it was the same type then you could change it in place.

Thyl
Calcite | Level 5

None of this worked. It's just gray before i even input anything more so i doubt it can see i want to put a character there. And the variable is character anyway. This should work. I read few articles on the subject   and the examples look like my update attempt. There are missing values in the column. May this couse the problem?

Reeza
Super User

roznica<1000 indicates that roznica field would be numeric to be, but then you reassign it a value of 'Rank1' which is character.

As long as you realize that 200>1000 in character language I guess the following is what you want in terms of programming. Logically it doesn't make sense to me.

You have an additional bracket, are missing the end and are also missing the semicolon at the end. In terms of the IDE, I don't believe that the case and other key words are coloured when using it in an update statement, but it still works.

proc sql;

update anacars.rabat

set roznica=

case                                                       <------------------------------------------

when roznica <'1000' then 'Rank1' end;

select * from anacars.rabat;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 833 views
  • 0 likes
  • 4 in conversation