08-26-2017 10:32 AM
|ASSET TIPE||DOB||VEHICLE_AGE||VEHICLE COST||REG_DATE||SNAPSHOT_DATE||TERM|
write sql procedure using dataset_initial to calculate total vehicle cost (TOT_VEH_COST) by ASSETTYPE for vehicles not older than 12.
i think that :
select Assettype,SUM(Vehicle_cost) as TOTAL_COST
group by Assettype;
08-26-2017 11:15 AM - edited 08-26-2017 11:15 AM
No, it's not correct.
You're not accounting for the vehicles not older than 12 properly - mostly I think you're using the wrong variable.
08-28-2017 02:36 PM
You don't really provide enough information.
Vehicles not older than 12? Is that records with a vehicle_age value of less than or equal to 12? Or is it Term vlaues? Or is it current date minus reg_date? Or is it something else?
Let's assume a term amount <= 12.
So with data like
data stuff; input ASSET_TYPE $4. VEHICLE_COST TERM; datalines; NEW 15000 12 USED 10000 12 NEW 20000 24 USED 5000 36 NEW 15000 6 NEW 15000 9 USED 10000 6 ; run;
You can use the SQL you posted
proc sql; create table cost_by_asset_type as select asset_type, sum(vehicle_cost) from stuff where term <=12 group by asset_type; quit;
and come up with
Is this what you want?