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

Hello:

 

I try to update the multiple values in different columns.  I wrote a code below,  The log shows in the Syntax error.  Please help.  Thanks.

 

338 PROC SQL;
339 update work.test
340 set age=age
341 case
----
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, !!, (, *, **, +, ',', -, '.', /,
WHERE, ||.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

342 when age in (1,2,3,4,5) then age=1
----
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, !, &, AND, OR, |.

ERROR 76-322: Syntax error, statement will be ignored.

343 when age in (6,7,8,9) then age=2
344 when age in (10,11,12,13) then age=3
345 end;
346 , set marital=marital
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

347 case
348 when marital in (2, 4) then marital=2
349 end;
350 , set education=education
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

351 case
352 when education in (1,2) then education=1
353 when education in (3,4) then education=2
354 when education in (5.6) then education=3
355 end;
356 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, its probably a good idea to start from the basics then.  Your code has lots of problems.  This code demonstrates how to to an update - note it will affect all rows as there is no where.

data test;
  set sashelp.class;
run;

proc sql;
  update TEST 
  set AGE=case when AGE in (14,13) then 1
               when AGE in (11,12) then 2
               else 3 end,
      HEIGHT=case when HEIGHT < 63 then 1
                  else 2 end;
quit;
      

You will see semicolon is only at the end of the SQL.  Variables are delimited by commas, set appears only once, case statement is different.  These are basic SQL things which you should be learning before trying to do more advanced tasks like updating and joining.  (and presenting code in a the code window - {i} and using consistent casing/indetation and such like makes reading code easier).

View solution in original post

4 REPLIES 4
ybz12003
Rhodochrosite | Level 12

My original codes is list below:

 

PROC SQL;
update work.test
set age=age
case
when age in (1,2,3,4,5) then age=1
when age in (6,7,8,9) then age=2
when age in (10,11,12,13) then age=3
end;
, set marital=marital
case
when marital in (2, 4) then marital=2
end;
, set education=education
case
when education in (1,2) then education=1
when education in (3,4) then education=2
when education in (5.6) then education=3
end;
quit;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Am afraid there is several problems with that code, semicolons all over the place, case statements invalid, assignments wrong, no from, and update doesn't work like that anyways.  Too much to waste time fixing.  Why not just do a very simple datastep:

data want;
  set have;
  select(age);
    when (1,2,3,4,5) age=1;
    when (6,7,8,9) age=2;
    otherwise age=3;
  end;
...
run;

Alternatively post some test data in the form of a datastep so that we have something to work with

ybz12003
Rhodochrosite | Level 12

Thanks for your advice.  I'm trying to learn how to change the value in PROC SQL.  I have done this in data step.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, its probably a good idea to start from the basics then.  Your code has lots of problems.  This code demonstrates how to to an update - note it will affect all rows as there is no where.

data test;
  set sashelp.class;
run;

proc sql;
  update TEST 
  set AGE=case when AGE in (14,13) then 1
               when AGE in (11,12) then 2
               else 3 end,
      HEIGHT=case when HEIGHT < 63 then 1
                  else 2 end;
quit;
      

You will see semicolon is only at the end of the SQL.  Variables are delimited by commas, set appears only once, case statement is different.  These are basic SQL things which you should be learning before trying to do more advanced tasks like updating and joining.  (and presenting code in a the code window - {i} and using consistent casing/indetation and such like makes reading code easier).

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
  • 4 replies
  • 9965 views
  • 1 like
  • 2 in conversation