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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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