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

Hello,

I have two data sets, where one column is exactly the same and another holds different values. There are two simple data sets:

First data set:                         Second data set:

  

             

OBS     Name       Income               OBS      Name       Income                    

1         John          1201                   1           John         5566

2         David         1602                   2           David        5981

3         Karen        1553                   3           Karen       8930  

                  

As You can see, the names are duplicating, however the income column is different.

The question would be - how can I make a single data set where:

1) The names do not duplicate anymore.

2) The data in 'income' column would be calculated as an average value from first and second data sets.

3) If possible, are there more than one solution for this situation? Please suggest the most efficient ways to do this,

because I'll need to apply suggested solution for many big data sets.


The output should be:

New data set

Name     Income

John       3383,5       which is average of two previous data sets - ((1201+5566)/2)

David      3791,5

Karen     5241,5

Thank You.

1 ACCEPTED SOLUTION

Accepted Solutions
Sudhakar_A
Calcite | Level 5

another simple method.

data fin;

    merge one two(rename=(income=income1));

     by name;

     avgincome=mean(income, income1);    

run;

View solution in original post

3 REPLIES 3
SandyH
Calcite | Level 5

1. set the two datasets with two columns (name, income).

2. proc sql;

       avg(income) as income

      group by name

OR

merge the two datasets by name, with three columns. then calculate average.

art297
Opal | Level 21

or. slightly faster:

proc sql;

  create table want as

    select name,avg(income) as income

      from

       (select * from one

         outer union corr

           select * from two)

        group by name

  ;

quit;

Sudhakar_A
Calcite | Level 5

another simple method.

data fin;

    merge one two(rename=(income=income1));

     by name;

     avgincome=mean(income, income1);    

run;

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