BookmarkSubscribeRSS Feed
savannah
Calcite | Level 5

 

 

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+

8 REPLIES 8
pau13rown
Lapis Lazuli | Level 10

data new;

retain sumtotal;

set get1;

auto1=auto_1/PE;

:

etc:

:

total=sum(of auto1-auto4);

sumtotal=sumtotal+total;

run;

?

savannah
Calcite | Level 5

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.

Reeza
Super User

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.


 

savannah
Calcite | Level 5

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
Reeza
Super User

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

 

savannah
Calcite | Level 5

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

Reeza
Super User

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


 

savannah
Calcite | Level 5

I want to calculate the Auto/PE values and get a total and then a running cummulative total

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 8 replies
  • 969 views
  • 0 likes
  • 3 in conversation