06-11-2015 07:19 PM
I would like help to code this please ....
currently I have a data step that is coded:
retain accruingbal 3451.76;
.. 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?
retain accruingbal = value called Openingbal in dataset called Opening;
thanks for your help :-)
06-11-2015 11:57 PM
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:
if _N_ = 1 then do;
set opening(keep = openingbal);
accruingbal = openingbal;
06-12-2015 01:48 AM
You can use a macro variable and sql to automate this:
proc sql noprint;
select openingbal into :init_value from opening;
* make sure that opening has only one observation, or use a where condition to only get the observation you want;
retain accruingbal &init_value;
Edit: adapted my original posting to your variable/dataset names.