Help using Base SAS procedures

enter value from one dataset into another

Reply
Occasional Contributor
Posts: 6

enter value from one dataset into another

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 :-)

Trusted Advisor
Posts: 1,137

Re: enter value from one dataset into another

data daily1;

merge daily x;

by byvariable;

retain accruingbal;

accruingbal+amount;

run;



Please try this untested code.

Thanks,
Jag
Contributor dkb
Contributor
Posts: 53

Re: enter value from one dataset into another

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;

Super User
Posts: 7,782

Re: enter value from one dataset into another

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 3 replies
  • 230 views
  • 0 likes
  • 4 in conversation