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

data1.PNGdata2.PNG

I tried to merge both datasets based on the variables ClassVal0 and param. For some reason though the coding I used is not working. First I tried to update based using this code below before merging but it said SQL Update: ERROR: Subquery evaluated to more than one row.

proc sql;
	update bout.allm as a
	set ClassVal0 = (select (ClassVal0) 
	from nhns.chdsimplogtab as b 
	where a.Param = b.Param
	group by b.Param);
quit;

Then I just tried to combine them together based on this code below and it just didn't work out with values mismatched.

proc sql;
create table mamlogistictable as
select a.*, b.M_OR_CI, b.M_p_value, b.M_g_p_value
from btab.lnelmam_simplogtab a
left join bout.allm b
on a.ClassVal0 = b.ClassVal0
and a.Param = b.Param
order by Param;
quit;

What am I doing wrong? I'd appreciate the explanation.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I think you were arleady getting the right resuIts, but the ordering was confusing. I get decent results with :

 

proc sql;
create table mamlogistictable as
select  
    a.*, 
    b.M_OR_CI, 
    b.M_p_value, 
    b.M_g_p_value
from 
    sasforum.lnelmam_simplogtab a left join 
    sasforum.allm b on a.ClassVal0 = b.ClassVal0 and a.Param = b.Param
order by f_ord;
quit;

Replace sasforum with your own library names.

PG

View solution in original post

6 REPLIES 6
sas_apprenant
Fluorite | Level 6

It is "on" not "bon". The error was made while posting it.

Tom
Super User Tom
Super User

Please post data as text, not photographs.  Limit to enough variables and observations to demonstrate the issue.

 

As the error says to use a subquery to update a value with the UPDATE statement in SQL the subquery must return only one value.  Which of the many values to you want to use? Is there some way to pick the right one?  Perhaps you want the min or max value?

PGStats
Opal | Level 21

Based on the *pictures* of the data, the join should work. Try replacing the left join with an inner join. Please give a more detailed description of the missmatch that you obtain.

PG
sas_apprenant
Fluorite | Level 6

I tried the inner join and the output does not work with what I want. Essentially, I want to add the output of my adjusted regression analysis to simple regression with the adjusted odd ratios, CIs, and global p-value. Using inner join, I got the attached result (file added). Also, I added the files from the original. 

PGStats
Opal | Level 21

I think you were arleady getting the right resuIts, but the ordering was confusing. I get decent results with :

 

proc sql;
create table mamlogistictable as
select  
    a.*, 
    b.M_OR_CI, 
    b.M_p_value, 
    b.M_g_p_value
from 
    sasforum.lnelmam_simplogtab a left join 
    sasforum.allm b on a.ClassVal0 = b.ClassVal0 and a.Param = b.Param
order by f_ord;
quit;

Replace sasforum with your own library names.

PG
sas_apprenant
Fluorite | Level 6

I realized I was on the right track and figured it out. Thank you for the guidance. 

I appreciate it!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 786 views
  • 0 likes
  • 3 in conversation