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

 

 

 

I am trying to combine the two update statements into one.

 

The fist clause:

 

proc sql;
update dataset
set var1 = 
case 
	when var1 is missing and filter_var = 1  then "new value"
	else var1
	end 
;quit;


 The second clause:

 

proc sql;
update dataset
set var2 = 
case 
when var2 is missing and filter_var = 1 then "new value"
else var2
end 
;quit;

 

My try at combining the two clauses into one:

 

proc sql;
update dataset
set var1 = 
case 
when var1 is missing and filter_var = 1 then "new value"
else var1
end,
set var2 = 
case 
when var2 is missing and filter_var = 1 then "new value"
else var2
end 
;quit;
 

 

However I get an error, expecting a ",".

 

Any ideas if this is possible?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Try

proc sql;
update dataset
set
  var1 = case 
    when var1 is missing and filter_var = 1 then "new value"
    else var1
  end,
  var2 = case 
    when var2 is missing and filter_var = 1 then "new value"
    else var2
  end 
;
quit;

Either omit the second "set", or the comma immediately before it.

See the syntax description in http://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#p0ci36zwxhm1xdn1a9...

View solution in original post

2 REPLIES 2
Reeza
Super User

I believe the syntax is 

 

SET <list of changes>

 

Try removing the second SET. 

Kurt_Bremser
Super User

Try

proc sql;
update dataset
set
  var1 = case 
    when var1 is missing and filter_var = 1 then "new value"
    else var1
  end,
  var2 = case 
    when var2 is missing and filter_var = 1 then "new value"
    else var2
  end 
;
quit;

Either omit the second "set", or the comma immediately before it.

See the syntax description in http://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#p0ci36zwxhm1xdn1a9...

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!

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.

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