BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pchappus
Obsidian | Level 7

I don't understand why this isn't working. I want to sum up all the Qtrly_Paids for each Paid_Qtr. I know how to do this in proc sql but can't figure out why this isn't working in a data step.

 

DATA RDS_Final;
	RETAIN PAID_QTR QTR_Paids;
	SET work.RDS_Qtr_Pds(KEEP=Paid_Qtr Qtr_Paids);
	
	FORMAT 
		Pd_Clm_From_Rds COMMA20.;
	
	BY Paid_Qtr;
	IF first.Paid_Qtr THEN Pd_Clm_From_Rds = 0;
	Pd_Clm_From_Rds + Qtr_Paids;
	
	DROP Qtr_Paids;
RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You got most of the way there.

 

Your result includes all the original observations, with the cumulative total so far.  

 

To subset and get only the final totals, add this statement at the end of the DATA step:

 

if last.Paid_Qtr;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

log message plz

Astounding
PROC Star

You got most of the way there.

 

Your result includes all the original observations, with the cumulative total so far.  

 

To subset and get only the final totals, add this statement at the end of the DATA step:

 

if last.Paid_Qtr;

pchappus
Obsidian | Level 7

I really need to look into first. last. and by processing more... 

 

It seems like a simple concept that I'm missing.

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!

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