BookmarkSubscribeRSS Feed
deleted_user
Not applicable
data is as follows
date meter demand cal;
1 A 5 5
2 B 10 15
3 C 15 30
4 D 20 50
5 E 25 75
6 F 30 105
7 G 35 140
8 H 40 1 80

in this table
there are three variables and "cal" is the result i require
so
i need the code such as i get the cumulative sum as shown in "Cal"
my input are date,meter(charachter) and demand and i need "cal" which
is shown in the table
and i need to sort it by meter and date
like for meter A (date 1 to 😎 its "cal"
then meter B (date 1 to 😎 its "cal"
so, please do reply if u have an answer for this query
thanks
4 REPLIES 4
DanielSantos
Barite | Level 11
Hi!

First sort the data as you wish.
see PROC SORT procedure: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/sort-overview.htm

Then through datastep add the DEMAND variable to a CAL retained variable.
see how to RETAIN a value: http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
ballardw
Super User
An approach without datastep would be:

proc sort data=; by meter date;run;

proc freq data= noprint;
by meter;
tables date/list outcum out= (drop=percent cum_pct rename=(count=demand cum_freq=cal));
weight demand;
run;

You'll have labels for the demand and cal variable related to frequency count but that's fixeable lots of ways. May not do what you want if any demand values are missing or negative.
kggunes
Calcite | Level 5
A CUMSUM
1 5 5
2 10 15
3 15 30
4 20 50
5 25 75
6 30 105
7 35 140
8 40 180

Hello,

I just want to calculate CUMSUM column (cumulative sum of column A). Do I still have to use RETAIN? I found the following sample code, but;

data a;
set a;
xsum + x;
run;


Thanks
ChrisNZ
Tourmaline | Level 20
using the syntax

A + B;

(with no = sign) does an implicit retain.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 15651 views
  • 0 likes
  • 5 in conversation