BookmarkSubscribeRSS Feed
franph
Calcite | Level 5

Hi

I would like help to code this please ....

currently I have a data step that is coded:

data daily1;

set daily;

retain accruingbal 3451.76;

accruingbal+amount;

run;

.. but it means I manually have to enter the amount each time I run it

how can I write it to get the amount from another dataset?

data daily1;

set daily;

retain accruingbal = value called Openingbal in dataset called Opening;

accruingbal+amount;

run;

thanks for your help 🙂

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

data daily1;

merge daily x;

by byvariable;

retain accruingbal;

accruingbal+amount;

run;



Please try this untested code.

Thanks,
Jag
dkb
Quartz | Level 8 dkb
Quartz | Level 8

Presumably you are confident that there is only one observation in the "Opening" dataset?  You can read it the first time through the data step but not thereafter:


data daily1;

drop openingbal;

if _N_ = 1 then do;

  set opening(keep = openingbal);

  accruingbal = openingbal;

end;

set daily;

accruingbal+amount;

run;

Kurt_Bremser
Super User

You can use a macro variable and sql to automate this:

proc sql noprint;

select openingbal into :init_value from opening;

quit;

* make sure that opening has only one observation, or use a where condition to only get the observation you want;

data daily1;

set daily;

retain accruingbal &init_value;

accruingbal+amount;

run;

Edit: adapted my original posting to your variable/dataset names.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1279 views
  • 0 likes
  • 4 in conversation