SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to convert the SQL update statement to SAS update statement?

Reply
Regular Contributor
Posts: 168

How to convert the SQL update statement to SAS update statement?

Hi All,

 

    I have trouble to convert the following SQL update statement to SAS Update statement, could you please help me with this? Thank you!

 

   SQL update statement:

Proc sql;

update TableA

SET InstituteID = LocationID

FROM TableA as f

LEFT JOIN TableB as d ON f.MainLocation = d.LocationName

WHERE InstituteID is NULL

;

Quit;

Super User
Posts: 7,781

Re: How to convert the SQL update statement to SAS update statement?

proc sort data=tablea;
by mainlocation;
run;

proc sort data=tableb;
by locationname;
run;

data tablea;
merge
  tablea (in=a)
  tableb (in=b rename=(locationname=mainlocation))
;
by mainlocation;
if a;
if b and missing(instituteid ) then instituteid = locationid;
drop locationid;
run;

The success depends on the relationship between the tables with regards to the key variable (1:1, 1:n, m:1, m:n).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 168

Re: How to convert the SQL update statement to SAS update statement?

Posted in reply to KurtBremser

Thanks!

Respected Advisor
Posts: 4,920

Re: How to convert the SQL update statement to SAS update statement?

Hi @Jade_SAS,

 

Does this update query work in SAS/SQL? The documentation doesn't include the possibility of a from clause in an update query.

PG
Ask a Question
Discussion stats
  • 3 replies
  • 162 views
  • 0 likes
  • 3 in conversation