BookmarkSubscribeRSS Feed
GKati
Pyrite | Level 9

 

 

Hello,

 

I'm trying to add up mean_costs of claims over clients. For some claims and certain years I don't have the mean-cost, which appears as missing in my dataset. In these cases I want overall-costs for that client to be also missing. How do I put this in my code below. Sorry I am not very good in SQL. Thanks 

 

proc sql;

  create table work.final_claims as

  select *

 

  , sum(mean_cost_2012) as overall_cost1016

  from work.final_claims

  group by client, year

  order by client year;

quit;

 

Have   
clientyearmean_cost_2012Overall_Cost
120122557
120123257
22012232232
22013883883
32012232232
32012.232
32013323323

 

Want

clientyearmean_cost_2012Overall_Cost
120122557
120123257
22012232232
22013883883
32012232.
32012..
32013323323
3 REPLIES 3
LinusH
Tourmaline | Level 20

Could you please attach/show some sample have and want tables?

Data never sleeps
GKati
Pyrite | Level 9
Sure, see message edited above. Thx
Ksharp
Super User

data Have;	 	 	 
input client	year	mean_cost_2012	;
cards;
1	2012	25	57
1	2012	32	57
2	2012	232	232
2	2013	883	883
3	2012	232	232
3	2012	.	232
3	2013	323	323
;
run;

proc sql;
  create table work.final_claims as
  select *
  ,case when exists(select * from have where mean_cost_2012 is missing and client=a.client and year=a.year)
then .  else sum(mean_cost_2012) end as overall_cost1016
  from work.have as a
  group by client, year
  order by client, year;
quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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