data new;
set work.get1;
do i=1 by 1 until (last.City);
Total(i)=sum(of auto_1/PE-auto_4/PE);
end;
run;
I would like to divide the $amount of each automobile by a factor called PE and then add to a running total for that row. Indefinite number of cities.
CITY Auto_1 Auto_2 Auto_3 Auto_4 PE Total
City 1 Total 1
City 2 Total 2
City 3 Total 3
. .
. .
.
..
do
sum_range=sum(of a1-a5);
run;
retain total1 =0;
total1=total1+
data new;
retain sumtotal;
set get1;
auto1=auto_1/PE;
:
etc:
:
total=sum(of auto1-auto4);
sumtotal=sumtotal+total;
run;
?
Thank you for your response. How do I do that for all the listed cities for (column name=CITY) and I do not know the number of cities.
It doesn't matter. SAS does that automatically.
If it doesn't work post your code.
@savannah wrote:
Thank you for your response. How do I do that for all the listed cities for (column name=CITY) and I do not know the number of cities.
i think you have use the syntax 'divide'
want a running total
data new_mid_total;
set work.ok_mid1;
do i=1 by 1 until (last.City);
Total(i)=sum(of divide(Auto_1/PE)-divide(Auto_2/PE));
end;
run;
i get an error:
Show an example of your data and what you want as output and we can help suggest methods. Showing us problematic code isn't going to keep moving this forward.
If it's resolved, please mark it as solved and post the solution for future users.
@savannah wrote:
i think you have use the syntax 'divide'
want a running total
data new_mid_total;
set work.ok_mid1;
do i=1 by 1 until (last.City);
Total(i)=sum(of divide(Auto_1/PE)-divide(Auto_2/PE));
end;run;
i get an error:
ERROR: Undeclared array referenced: Total.ERROR: Undeclared array referenced: divide.ERROR: Variable divide has not been declared as an array.Thanks for your help
CITY Auto_1 Auto_2 Auto_3 Auto_4 PE Auto1/PE Auto2/PE....>> Total Cummulative Total
City 1 40 60 65 55 0.5 Total 1 Total 1
City 2 . . 44 54 1.2 Total 2 Total 1+Total2
City 3 32 41 45 0.9 Total 3 Total 1 + total2 + total3
data has missing values
Total is of all Auto/PE for that row
Hope that helps
Is that what you want or what you have? Please clearly identify which is already calculated,w hat you want calculated and what the values would be for the data shown so we can verify the calculations on our side.
@savannah wrote:
CITY Auto_1 Auto_2 Auto_3 Auto_4 PE Auto1/PE Auto2/PE....>> Total Cummulative Total
City 1 40 60 65 55 0.5 Total 1 Total 1
City 2 . . 44 54 1.2 Total 2 Total 1+Total2
City 3 32 41 45 0.9 Total 3 Total 1 + total2 + total3
data has missing values
Total is of all Auto/PE for that row
Hope that helps
I want to calculate the Auto/PE values and get a total and then a running cummulative total
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.