Can anyone help with my issue?
i am stuck in this problem for few days
the Note listed below is keep coming out:
NOTE: The query requires remerging summary statistics back with the original data.
this is my code:
PROC SQL;
CREATE TABLE
WrittenData as
SELECT
CASE WHEN Product IN ('371004', '371047','376003','374008') THEN 'PC' ELSE 'AH' END as BusinessUnit
,Period
,UWYear
,ExposurePeriod
,SUM(GWP) as GWP
,SUM(NWP) as NWP
,SUM(Commission) as Commission
,SUM(GWP_USD) as GWP_USD
,SUM(NWP_USD) as NWP_USD
,SUM(Commission_USD) as Commission_USD
FROM Written
WHERE
Written.Period >= 201201
AND
Written.Pac IN ('GMMAM')
GROUP BY CASE WHEN Product IN ('371004', '371047', '376003', '374008') THEN 'PC' ELSE 'AH' END, Period, UWYear, ExposurePeriod
;
QUIT;
and this is my log
You've run into a shortcoming of the SAS SQL compiler that I have adressed in https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhance-the-quot-group-by-quot-evaluation-logic-...
Use the calculated variable in the group by:
proc sql;
create table writtenData as
select
case
when Product in ('371004','371047','376003','374008') then 'PC'
else 'AH'
end as BusinessUnit,
Period,
UWYear,
ExposurePeriod,
sum(GWP) as GWP,
sum(NWP) as NWP,
sum(Commission) as Commission,
sum(GWP_USD) as GWP_USD,
sum(NWP_USD) as NWP_USD,
sum(Commission_USD) as Commission_USD
from Written
where
Written.Period >= 201201
and
Written.Pac in ('GMMAM')
group by
calculated BusinessUnit,
Period,
UWYear,
ExposurePeriod
;
quit;
Compare the look of my code with your code as posted; proper visual formatting goes a long way in understanding what's going on:
@harrylui wrote:
Can anyone help with my issue?
i am stuck in this problem for few days
the Note listed below is keep coming out:
NOTE: The query requires remerging summary statistics back with the original data.
this is my code:
PROC SQL;
CREATE TABLE
WrittenData as
SELECT
CASE WHEN Product IN ('371004', '371047','376003','374008') THEN 'PC' ELSE 'AH' END as BusinessUnit
,Period
,UWYear
,ExposurePeriod
,SUM(GWP) as GWP
,SUM(NWP) as NWP
,SUM(Commission) as Commission
,SUM(GWP_USD) as GWP_USD
,SUM(NWP_USD) as NWP_USD
,SUM(Commission_USD) as Commission_USD
FROM Written
WHERE
Written.Period >= 201201
AND
Written.Pac IN ('GMMAM')
GROUP BY CASE WHEN Product IN ('371004', '371047', '376003', '374008') THEN 'PC' ELSE 'AH' END, Period, UWYear, ExposurePeriod
;
QUIT;
and this is my log
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;61626364 PROC SQL;65 CREATE TABLE66 WrittenData as67 SELECT68 CASE WHEN Product IN ('371004', '371047','376003','374008') THEN 'PC' ELSE 'AH' END as BusinessUnit69 ,Period70 ,UWYear71 ,ExposurePeriod72 ,SUM(GWP) as GWP73 ,SUM(NWP) as NWP74 ,SUM(Commission) as Commission75 ,SUM(GWP_USD) as GWP_USD76 ,SUM(NWP_USD) as NWP_USD77 ,SUM(Commission_USD) as Commission_USD78 FROM Written79 WHERE80 Written.Period >= 20120181 AND82 Written.Pac IN ('GMMAM')83 GROUP BY CASE WHEN Product IN ('371004', '371047', '376003', '374008') THEN 'PC' ELSE 'AH' END, Period, UWYear,83 ! ExposurePeriod84 ;NOTE: The query requires remerging summary statistics back with the original data.NOTE: Table WORK.WRITTENDATA created, with 821 rows and 10 columns.85 QUIT;NOTE: PROCEDURE SQL used (Total process time):real time 0.01 secondscpu time 0.01 seconds86878889 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;102
Lets start by making that code readable, by adding formatting, using the code window (its the {i} above post area), and by not shouting the code:
proc sql; create table writtendata as select businessunit ,period ,uwyear ,exposureperiod ,sum(gwp) as gwp ,sum(nwp) as nwp ,sum(commission) as commission ,sum(gwp_usd) as gwp_usd ,sum(nwp_usd) as nwp_usd ,sum(commission_usd) as commission_usd from (select *, case when product in ('371004', '371047','376003','374008') then 'PC'
else 'AH' end as businessunit from written where period >= 201201 and pac='GMMAM') group by businessunit, period, uwyear, exposureperiod; quit;
You will see that I do the filtering in a sub-query.
thank you! I solved it!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.