BookmarkSubscribeRSS Feed
Biscuitmuncher
Calcite | Level 5

Hi,

Hopefully somebody may be able to give me a steer as I’m fairly new to base SAS. I’m preparing a dataset for import to VA (version 7.3).I have the following dataset following a transpose procedure. I  am trying to construct a cumulative total for each product by its stage (A,R and U), its status, area and town. I had thought of using by variables in a data step would be the way forward but I have not been able to get it to work. Does anybody have any suggestions please?

 

Dayno

Product

Status

Area

Town

Stage A

StageR

StageU

Daily_Tot

0

DGSEPCHI

E

HWB

NMSW

2

2

.

4

0

DGSEPCHI

H

HWB

NMSW

23

18

4

45

0

DGSEPCHI

O

HWB

APS

2

2

.

4

0

DGLW4

H

SASS

CJC

4

5

5

14

12

DGSEPCHI

H

HWB

NMSW

.

.

.

0

27

DGLW4

H

SASS

CJC

1

4

.

5

39

DGLW4

H

SASS

CJC

.

.

.

0

40

DGLW4

H

SASS

CJC

1

6

2

9

41

DGLW4

H

SASS

CJC

.

.

6

6

43

DGLW4

H

SASS

CJC

1

.

.

1

47

DGLW4

H

SASS

CJC

.

.

.

0

48

DGSEPCHI

H

HWB

APS

1

.

.

1

8 REPLIES 8
mkeintz
PROC Star

Please show the forum

 

  1. What the output with cumulative totals should look like,
  2. The program with BY statements that you tried, along with the results

Then you will get a better level of help.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Biscuitmuncher
Calcite | Level 5

Thank you for responding. I have included the output I am trying to achieve earlier in the thread. Any thoughts and ideas would be great.

 

PaigeMiller
Diamond | Level 26

I  am trying to construct a cumulative total for each product by its stage (A,R and U), its status, area and town.


Cumulative total of which variable?

--
Paige Miller
Biscuitmuncher
Calcite | Level 5

Hi,

 

Thank you so much for the response. Essentially I am trying to obtain a cumulative total for each product by area, town and status. Something along the lines of the attached. Any steer you can give will be great. Thank you.

DaynoProductStatusAreaTownStage AStageRStageUCum Area _Stage ACum Town_ Stage ACum Status Stage A
0DGSEPCHIEHWBNMSW22.222
0DGSEPCHIHHWBNMSW23184252523
0DGSEPCHIOHWBAPS22.2722
0DGLW4HSASSCJC455444
12DGSEPCHIHHWBNMSW...272523
27DGLW4HSASSCJC14.555
39DGLW4HSASSCJC...555
40DGLW4HSASSCJC162666
41DGLW4HSASSCJC..6666
43DGLW4HSASSCJC1..777
47DGLW4HSASSCJC...777
48DGSEPCHIHHWBAPS1..883
PaigeMiller
Diamond | Level 26

Thank you so much for the response. Essentially I am trying to obtain a cumulative total for each product by area, town and status. Something along the lines of the attached. Any steer you can give will be great. Thank you.

 

I'm still struggling with your wording. It seems you want a cumulative total for each product and area, and then another cumulative total for each product and town, and then a third cumulative total by each product and status. Is that what you want?

 

Typically, to compute cumulative totals, you have to first sort the data into the groupings of interest, in order to compute cumulative totals.

 

If so, you would need to do a sort by product and area and compute cumulative totals for that case. Then do another sort by product and town, and compute cumulative totals for that case. Then do another sort by product and status, and compute cumulative totals for that case.

 

Furthermore, in order for cumulative totals to be correct, you need to have the correct ordering withing your groups. You haven't mentioned the variable DAYNO, is that the proper ordering of the data within the groups??

--
Paige Miller
Biscuitmuncher
Calcite | Level 5

Hi,

Apologies. Essentially you are correct. I am indeed after a cumulative total over a period of days, for a.) product and area, product and town, product and status.

 

I will give the sort procedures a go.

 

Thankyou.:-)

Reeza
Super User

It may be better to do this in VA directly as a calculated column if you want an interactive variable that adjusts based on filters and such.

 

This is for median, but can probably be used for a SUM as well. 

https://stackoverflow.com/questions/50334174/how-do-i-create-a-cumulative-median-field-in-sas-va-7-4...

Biscuitmuncher
Calcite | Level 5

Hi,

Firstly thanks for all the replies to date. I am not sure that SAS VA version 7.3. would allow a daily cumulative total, but I will have a look. The link is very helpful .

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 873 views
  • 0 likes
  • 4 in conversation