BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Good Eveyone

 

How to find cumulative sum for height in class library 

using proc sql

data dsn;
set sashelp.class;
run;

proc sort data=dsn;
by age;
run;

data dsn1;
set dsn;
by age;
retain cumulative 0.;
if first.height then height+cumulative;
else  cumulative+height;
run;
5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

If you simply want a cumulative sum of heights and do not want to consider by-groups, then no by-statement is needed in the data step. Simply do

 

proc sort data=sashelp.class out=dsn;
    by age;
run;

data want;
    set dsn;
    cumulative+height;
run;

 

 

BrahmanandaRao
Lapis Lazuli | Level 10

i want using proc sql sort by age variable  and output cumulative sum of height

PeterClemmensen
Tourmaline | Level 20

Why? So much easier with the data step

BrahmanandaRao
Lapis Lazuli | Level 10

Hi draycut 

its just do for homework 

Kurt_Bremser
Super User

Dead simple:

  • create table
  • select age
  • also select sum(height) as cumulative
  • from sashelp.class
  • group by age

Build the SQL code by following the hints, and let us see what you come up with.

As already stated in another thread, I will not insult your intelligence by spoon-feeding you this very simple exercise.

 

PS a home exercise is for you to solve. If you can't, there's three possibilities:

  • you don't have what it takes for the course; drop out of the course and do something you're equipped for
  • you did not follow your teacher properly; be more attentive in the future
  • your teacher is not capable; take the course from someone else

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!

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