BookmarkSubscribeRSS Feed
harrylui
Obsidian | Level 7

hi all!

 

i am struck in DATA Transforming from SQL TO SAS

 

the answers given by SAS AND SQL don't match

 

can anyone do me a favour?

 

this is my SQL coding 

 

create table ClaimMedLL as 
SELECT
Claim.Period
,Claim.UWYear
,Claim.EventPeriod
,SUM(Claim.NTD_Incurred_Loss_Excl_Reval_Ledger) as MedL
,SUM(Claim.NTD_Incurred_Loss_Excl_Reval_USD) as MedL_USD
FROM Claim
WHERE ClaimNo IN (
SELECT ClaimNo FROM Claim GROUP BY ClaimNo HAVING SUM(Claim.NTD_Incurred_Loss_Excl_Reval_USD) > 50000
)
AND Claim.Pac IN ('GMMAN')
GROUP BY Period, UWYear, EventPeriod

 

i just simply add the proc sql and run into this coding

 

here is my screen cap of my portion of data set claim

 

ObsPeriodUWYearEventPeriodPacProductPolicyNoClaimNoClaimantNoCoverageCodeNTDIndemnityLossPaidUSDNTDClaimExpensePaidUSDNTDReserveChangeExclRevalUSDNTDIncurredLossExclRevalUSDNTDIndemnityLossPaidLedgerNTDClaim_ExpensePaidLedgerNTDReserveChangeExclRevalLedgerNTDIncurredLossExclRevalLedger
12018012000200007FAAMC370204HID09519134.05E+091PPFR00000000
22018012000201501 371901KCANC595864.04E+091 96075.750-96075.8.7500000-750000.
32018012000201702 371901MOP005210C4.04E+091 0139.890.010920.
42018012000201703 3719010442890CCG4.04E+091 1694365.47-4.13223.942853-31.23.
52018012000201706 371901HCGNA001334.04E+091 0139.890.010920.
62018012000201706 371901PGC04447244.04E+091 0267.990.020920.
72018012000201707 37190187TB46734.04E+091 099.92-4.0780-31.23.
82018012000201707 371901HCGNA001334.04E+091 0267.990.020920.
92018012000201707 371901M-12364.04E+091 01797.470.014031.670.
102018012000201708 3719012MC-8000354.04E+091 510.610-512.4.3986.030-4000.
112018012000201708 371901M-10214.04E+091 1944.440-20000.15178.960-156127.
122018012000201708 371901M-10214.04E+091 0139.890.010920.
132018012000201708 371901M-10214.04E+091 0139.890.010920.
142018012000201708 371901M-10214.04E+091 0214.570.016750.
152018012000201708 371901M-10214.04E+091 000.000.
162018012000201709 371901M-10214.04E+091 0139.890.010920.
172018012000201709 371901M-10214.04E+091 0139.890.010920.
182018012000201709 371901M-10214.04E+091 0139.890.010920.

 

 

2 REPLIES 2
ballardw
Super User

Show the "SAS" code that doesn't match.

 

Note that if you mean data step code then the SUM function for a data step works on a single row, not across rows as the SQL sum aggregate function.

 

Typically SQL Sum by group translates to Proc Means or Summary with Group by variables becoming CLASS variables.

But you would not be able to use where statement referencing a second data set so the data would have to be reduced prior to the proc.

harrylui
Obsidian | Level 7


proc sql;
create table ClaimMedLL as
SELECT
Period
,UWYear
,EventPeriod
,SUM(NTDIncurredLossExclRevalLedger) as MedL
,SUM(NTDIncurredLossExclRevalUSD) as MedL_USD
FROM Claim
WHERE ClaimNo IN (
SELECT Claim.ClaimNo FROM Claim GROUP BY Claim.ClaimNo HAVING SUM(Claim.NTDIncurredLossExclRevalUSD) > 50000
)
AND Claim.Pac IN ('GMMAM')
GROUP BY Period, UWYear, EventPeriod
;
run;

 

 

this is the code i am using 

 

is it really different from the SQL processing?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 684 views
  • 0 likes
  • 2 in conversation