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

Hi....I having problem getting the output I want when it comes to calculating "Total". I would like to only sum up the "ShowAmount" if the "Start" date is missing. Any suggestions.....Thanks.

 

 

data Have;
    length ID 8 TransDate $ 8 ShowAmount 8 Date $ 8 start $ 8 end $ 8;
    format ID best12. TransDate $char8. ShowAmount DOLLAR20.2 Date $char8. start $char8. end $char8.;
	infile datalines4 dlm='7F'x missover dsd;
    input ID : best32. TransDate : $char8. ShowAmount : best32. Date : $char8. start : $char8. end : $char8. ;
datalines4;
15220000720155020000720 
15220000804155020000804 
1522014080745020140807
1522014082710020140827 
152 .201409032014090320140930
152 .201410012014100120141008
1522015082745020150827  
152 .201509172015091720150930
152 .201510012015100120151031
15220151111700201511112015110120151130
152 .201512012015120120151210
1522016010855020160108  
152 .201601132016011320160131
15220160229450201602292016020120160229
152 .201603012016030120160323
152 .201604062016040620160430
152 .201605012016050120160531
152 .201606012016060120160629
;;;;

data want;
	set have;
	by ID TransDate notsorted;
		if first.ID then 
			Total = 0;
			Total + ShowAmount;
		if not missing(Start) then 
			Output;
run;


Want:
ID	TransDate	ShowAmount	Date	start	end	Total
152			20140903	20140903	20140930	3650
152			20141001	20141001	20141008	3650
152			20150917	20150917	20150930	4100
152			20151001	20151001	20151031	4100
152	20151111	$700.00	20151111	20151101	20151130	4800
152			20151201	20151201	20151210	4800
152			20160113	20160113	20160131	4650
152	20160229	$450.00	20160229	20160201	20160229	4650
152			20160301	20160301	20160323	4650
152			20160406	20160406	20160430	4650
152			20160501	20160501	20160531	4650
152			20160601	20160601	20160629	4650

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
It looks like you're doing summaries at different levels? PROC MEANS does this automatically as long as you specify your TYPES/WAYS correctly. I would recommend looking into that option instead.

View solution in original post

2 REPLIES 2
Reeza
Super User
It looks like you're doing summaries at different levels? PROC MEANS does this automatically as long as you specify your TYPES/WAYS correctly. I would recommend looking into that option instead.
ChrisNZ
Tourmaline | Level 20

Changed thread title from "Runnung Total" to "Running Total"

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 708 views
  • 0 likes
  • 3 in conversation