Help using Base SAS procedures

Need help- update case

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Need help- update case

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;


Accepted Solutions
Solution
‎06-17-2014 04:06 PM
Super User
Posts: 17,898

Re: Need help- update case

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


All Replies
Trusted Advisor
Posts: 1,204

Re: Need help- update case

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;

Valued Guide
Posts: 2,175

Re: Need help- update case

pwrhaps you only need to move the open (

update anacars.rabat

set roznica= ( select something

Super User
Posts: 17,898

Re: Need help- update case

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.

Occasional Contributor
Posts: 10

Re: Need help- update case

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?

Solution
‎06-17-2014 04:06 PM
Super User
Posts: 17,898

Re: Need help- update case

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 219 views
  • 0 likes
  • 4 in conversation