'PROC SQL not joining by string variable correctly

I have a query that I'm trying to run a join and it's not joining correctly. The query is below.

PROC SQL;
    CREATE TABLE indexscores AS
    SELECT ready.varname, 
        modules2.varlabel,
        ready.mean AS ready, 
        ecosocial.mean AS ecosocial, 
        capacity.mean AS capacity, 
        change.mean AS change,
        SUM(ready.mean,ecosocial.mean,capacity.mean,change.mean) AS score
    FROM ready
        LEFT OUTER JOIN ecosocial ON ready.varname=ecosocial.varname
        LEFT OUTER JOIN capacity ON ready.varname=capacity.varname
        LEFT OUTER JOIN change ON ready.varname=change.varname
        LEFT OUTER JOIN modules2 ON ready.varname=modules2.varname
    GROUP BY ready.varname, modules2.varlabel, 
        ready.mean, ecosocial.mean, capacity.mean, change.mean
    ORDER BY ready.varname;
RUN;

Below is a sample of it not showing the variable variable it should be.

Obs varname varlabel  ready ecosocial  capacity change score 
1   airqual   3.0455 3.5000    3.0455    3.4545  13.05 
2   alcohol   2.7692 3.7500    2.8718    3.5897  12.98 
3   alctraff  3.2051 3.7500    3.2308    3.9474  14.13 


Solution 1:[1]

I don't think you need the group by clause in this case as it is affecting the sum() function. This is based on my assumption that you simply want a row-level sum in score.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dev.T