Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bring two tables together and subtract two variables

Status
Not open for further replies.

ja01

Technical User
Dec 14, 2005
48
US
I have a newbie question below, Here is the code (I changed the name for security purposes)
proc sql;
/*Create main1 table*/
create table main1 as
select nameid, name,giftid,giftkey,giftplgkey,giftamtplg,
giftamount,gifttype,gifteffdat,chart_lku1
from name_full left outer join gifts_full
on nameid= giftid
quit;
/*Create payments*/
proc sql;
create table main1pay as
select nameid,nameformn,giftid,giftkey,giftplgkey,sum(giftamount) as payments,
gifttype,gifteffdat
from name_full left outer join gifts_full
on nameid=giftid
quit;

Now I want to subtract the sum(giftamount ) in the main1pay table from the giftamount in the main1 table and show the result in a field called PrevBal
Is this handled with a datastep or a new table and how is this done
 
What are you trying to sum in that second SQL step? You're bringing the same two tables together with the same variables from each as you did in the first, the only difference is you've put in a sum() function, however, as you're not grouping by a variable, this isn't going to work, it should generate an error message....
What are you trying to do? Not just in these steps, but overall, what is your aim?
 
What I am trying to do is back into the previous balance. For example, the first table produces the sum(giftamount) which essentially is the balance. By subtracting the balance from the payments(found in the payments) table, I hope to back into the Previous Balance. That is the reason I have set up two different tables
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top