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

Hello Team,

 

I am working on one of migration and has below statement

 

data strat.rep3;
merge strat.rep1 (in=uio) strat.rep2 (in=bnm);
by wclientcode wGroup mth ptpgroup;
if uio or bnm;
run;

 

Can someone please guide me what can be possible SQL statement for same ?

 

SELECT #rep1.wClientCode, #rep1.wGroup, #rep1.mth, #rep1.ptpGroup, #rep1.no_docapt, #rep1.ptpamtcapt,
#rep2.ptpamtdue, #rep2.no_kept, #rep2.ptpkeptamt, #rep2.no_dodue
FROM #rep1 INNER JOIN #rep2
ON #rep1.wClientCode = #rep2.wClientCode
AND #rep1.wGroup = #rep2.wGroup
AND #rep1.mth = #rep2.mth
AND #rep1.ptpGroup = #rep2.ptpGroup

 

But this statement not matching records of SAS output and SQL output. Can someone please guide me what is wrong here ?

 

Please let me know

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Your SQL code won't execute, as # is not allowed in SAS names.

 

There is a basic difference between SQL and the datastep merge, when there is a m:n relationship between the datasets. SQL will yield m*n records, while the merge will yield max(m,n) records. So you need to inspect both datasets for multiple occurences of a key variable combination.

 

The condition

if uio or bnm;

suggests you should be trying an outer join.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Your SQL code won't execute, as # is not allowed in SAS names.

 

There is a basic difference between SQL and the datastep merge, when there is a m:n relationship between the datasets. SQL will yield m*n records, while the merge will yield max(m,n) records. So you need to inspect both datasets for multiple occurences of a key variable combination.

 

The condition

if uio or bnm;

suggests you should be trying an outer join.

yudhishtirb
Calcite | Level 5

Hi KurtBremser

 

 

 

Reeza
Super User

Make sure to check results in the case of a Manu to many merge. If this isn't an issue with your data feel free to disregard this. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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