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

Hi SAS users,

 

thank you for taking your time. 

I have the dataset "Data1", with a structure like this:

2.PNG

 

And I have the Dataset "Sum1", which looks like this: 

 

3.PNG

 

I would like to merge those two so that for every row in data set "Data1" the corresponding values of variables sum1 and n from Dataset "Sum1" show up if the Jahr=Jahr and if ICBSUC=ICBSUC

 

So for example for every observation in data set "Data1" which in from Jahr 2010 and has an industry code ICBSUC of 10101010 the value in the variable sum1 should be 1.173... and the value in variable n should be 19. 

 

my current code looks like this: 

 
proc sort data=work.Data1;
by ICBSUC;
run;
 
proc summary data=Data1 nway;
    class  icbsuc Jahr;
    var KehrwertM;
    output out=sum1 sum=sum1 n=n;
run;
 
data Data2;
    merge Data1 sum1 (in =in2);
    by Jahr icbsuc;
    if in2;
run;
 
 
thank you for your help! 

 

 

 

 

  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

I believe the code what you wrote is correct, a minor update to include if in1 and in2 as below

 

data Data2;
    merge Data1(in=in1) sum1 (in =in2);
    by Jahr icbsuc;
    if in1 and in2;
run;

 

 

Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

I believe the code what you wrote is correct, a minor update to include if in1 and in2 as below

 

data Data2;
    merge Data1(in=in1) sum1 (in =in2);
    by Jahr icbsuc;
    if in1 and in2;
run;

 

 

Thanks,
Jag
smantha
Lapis Lazuli | Level 10
proc sort data=work.Data1;
by ICBSUC Jahr;
run;
 
proc summary data=Data1 nway;
    class  icbsuc Jahr;
    var KehrwertM;
    output out=sum1 sum=sum1 n=n;
run;
 
data Data2;
    merge Data1 sum1 (in =in2);
    by icbsuc Jahr;
    if in2;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 460 views
  • 1 like
  • 3 in conversation