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

Hi,

 

I encountered the same issue when I tried to update using the syntax below, and got an error message:

ERROR: Subquery evaluated to more than one row.

 

Could someone look at my code and see if this is a syntax error and help me correct it?

 

proc sql;
update lgddata.lgd_data_auto new
set auto_dfrt_other =
(select dfrt_other
from lgd2014.lgd_data_auto
where new.proc_yymm_dt = proc_yymm_dt);
quit;

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

It's not a syntax error, but a runtime problem because your subquery (apparently) yields more than one record, and the UPDATE assignment needs exactly one value to put in.

 

See what just this clause yields:

 

select dfrt_other 
from lgd2014.lgd_data_auto 
where new.proc_yymm_dt = proc_yymm_dt
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

It's not a syntax error, but a runtime problem because your subquery (apparently) yields more than one record, and the UPDATE assignment needs exactly one value to put in.

 

See what just this clause yields:

 

select dfrt_other 
from lgd2014.lgd_data_auto 
where new.proc_yymm_dt = proc_yymm_dt
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Bankshot
Obsidian | Level 7

Thanks Chris. When you say "subquery (apparently) yields more than one record", are you referring to the number of unique value (in this case dfrt_other)? I just did a check on the number of unique values by each date, it seems all dates have unique rate values:

proc sql;
select
proc_yymm_dt, count(distinct dfrt_other)
from lgd2014.lgd_data_auto
group by proc_yymm_dt
having count(distinct dfrt_other) > 1;
quit;

The above code yields to a blank result

PGStats
Opal | Level 21

As said in the error message, it is the number of rows that must be less than or equal to one. Rows with duplicate dfrt_other values are a problem too. Replace count(distinct dfrt_other) with count(*) to check the number of rows. 

PG
PGStats
Opal | Level 21

I suspect you are missing a condition in your where clause. Get the problematic dates with the query:

 

proc sql;
select a.proc_yymm_dt, count(*) as n
from 
	lgddata.lgd_data_auto as a inner join
	lgd2014.lgd_data_auto as b on a.proc_yymm_dt = b.proc_yymm_dt
group by a.proc_yymm_dt
having count(*) > 1;
quit;

(untested)

PG

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
  • 4 replies
  • 18187 views
  • 3 likes
  • 3 in conversation