Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
One approach migh be to sort by these values so they grouped, possibly within some other value such as a date. Then use by group with first. subproduct logic.
As always, showing some example data and the desired result for that data helps. See the instructions above. Include examples where the subtraction should not take place and some where it should, 2 or 3 of each should be sufficient to get started. If you have a lot of variables to "subtract" then only need to show one or two as the approach should be basically the same.
@subrat1 If you attach file, honestly I don't think it is convenient for any of us to help. Super user @RW9 has often many a time wrote requesting people to post in the form of a datastep and I wonder not many people are doing that.
Anyway, the below code works for your sample:
data want;
if (_n_ = 1) then do;
if 0 then set have;
declare hash myhash(dataset: "have(where=(Scenario='BUDGET'))");
myhash.definekey('Region','Country','Product','SubProduct','Quarter' );
myhash.definedata('Gross_Premium_Written','Net_Premium_Written');
myhash.definedone();
end;
set have(where=(Scenario='ACTUALS') rename=(Gross_Premium_Written=_Gross_Premium_Written Net_Premium_Written=_Net_Premium_Written));
rc=myhash.find();
if rc=0 then do;
Scenario='DELTA';
Gross_Premium_Written=_Gross_Premium_Written-Gross_Premium_Written;
Net_Premium_Written=_Net_Premium_Written-Net_Premium_Written;
output;
end;
drop rc _:;
run;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: