DATA Step, Macro, Functions and more

Explanation

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

Explanation

Hi,

 

Pls explain me the second point,

 

[1]Duplicate BY Values

Duplicates in the master and transaction data sets affect processing.

  • If duplicates exist in the master data set, only the first occurrence is updated because the generated WHERE statement always finds the first occurrence in the master.

  • If duplicates exist in the transaction data set, the duplicates are applied one on top of another unless you write an accumulation statement to add all of them to the master observation. Without the accumulation statement, the values in the duplicates overwrite each other so that only the value in the last transaction is the result in the master observation

 

Thanks


Accepted Solutions
Solution
‎06-21-2017 10:09 PM
Super User
Posts: 6,972

Re: Explanation

Maxim 4 comes into play. Just Try It:

data master;
input id value;
cards;
1 3
1 2
2 2
3 4
4 2
4 1
;
run;

data trans;
input id value;
cards;
1 6
2 4
3 5
3 6
4 7
4 8
;
run;

data master;
modify master trans;
by id;
run;

proc print data=master noobs;
run;

This is the result:

id    value

 1      6  
 1      2  
 2      4  
 3      6  
 4      8  
 4      1  

With ID 1, there's a duplicate in the master; only the first observation is updated, the second is unaffected.

With ID 3, there's a duplicate in the trans; only the last of that takes effect in the master.

With ID 4, both trans are worked into the first master, with the second taking effect; the second obs in the master stays unaffected.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,972

Re: Explanation

Please provide context.

Which documentation are you referring to?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎06-21-2017 10:09 PM
Super User
Posts: 6,972

Re: Explanation

Maxim 4 comes into play. Just Try It:

data master;
input id value;
cards;
1 3
1 2
2 2
3 4
4 2
4 1
;
run;

data trans;
input id value;
cards;
1 6
2 4
3 5
3 6
4 7
4 8
;
run;

data master;
modify master trans;
by id;
run;

proc print data=master noobs;
run;

This is the result:

id    value

 1      6  
 1      2  
 2      4  
 3      6  
 4      8  
 4      1  

With ID 1, there's a duplicate in the master; only the first observation is updated, the second is unaffected.

With ID 3, there's a duplicate in the trans; only the last of that takes effect in the master.

With ID 4, both trans are worked into the first master, with the second taking effect; the second obs in the master stays unaffected.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 95 views
  • 0 likes
  • 2 in conversation