BookmarkSubscribeRSS Feed
Shradha1
Obsidian | Level 7

I have a table in excel and I need to create a similar table in sas.

The table is like this:

DATE amount_at_start Spend savings amount_at_end charge_percentage charge_amount
17-Apr-21 100.00 10.00 0.00 110.00 10.00 0.03
18-Apr-21 110.00 0.00 0.00 110.00 10.00 0.03
19-Apr-21 110.00 0.00 0.00 110.00 10.00 0.03
20-Apr-21 110.00 0.00 0.00 110.00 10.00 0.03
21-Apr-21 110.00 20.00 40.00 90.00 10.00 0.02
22-Apr-21 90.00 0.00 0.00 90.00 10.00 0.02
23-Apr-21 90.00 0.00 0.00 90.00 10.00 0.02

 

The formulas used in the table are:

  • the first observation for amount_at_start is known to us, but thereafter next row onwards, amount_at_start=amount_at_end from previous row
  • spend and savings figures for each date is already given to us.
  • amount_at_end= (amount_at_start +spend _savings)
  • charge_percentage is known to us
  • charge_amount= (charge_percentage/100)*1/365*amount_at_end

This calculation is happening date wise row by row.

So if we have the first entry of amount_at_start, all the entries of spends and savings, and the charge_percentage given to us, how do we create a similar table in SAS

 

Any help on this would be much appreciated. Thanks!

2 REPLIES 2
s_lassen
Meteorite | Level 14

You have much better chances of getting an answer if you supply the input data (and maybe also the output you want) in a datastep, like this:

data have;
input date date9. amount_at_start Spend savings charge_percentage;
format date date9.;
cards;
17-Apr-21 100.00 10.00 0.00 10.00	
18-Apr-21 . 0.00 0.00 10.00
19-Apr-21 . 0.00 0.00 10.00
20-Apr-21 . 0.00 0.00 10.00
21-Apr-21 . 20.00 40.00 10.00
22-Apr-21 . 0.00 0.00 10.00
23-Apr-21 . 0.00 0.00 10.00
run;

I think you can get the data you want like this:

data want;
  set have;
  retain amount_at_end 0;
  if missing(amount_at_start) then amount_at_start=amount_at_end;
  amount_at_end=amount_at_start+spend-savings;
  charge_amount= round((charge_percentage/100)*1/365*amount_at_end,0.01);
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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