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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 751 views
  • 0 likes
  • 4 in conversation