hi all,
data t;
input m;
cards;
5
4
11
;
data t2;
set t;
k=m+;
output;
run;
I want result like this:
m k
5 5
4 9
11 20
data t;
input m;
cards;
5
4
11
;
data want;
set t;
retain k;
k+m;
run;
proc print;run;
Linlin
what is the purpose of retain statement?
Is K initially assume as zero?
Should I do following if I want to initial k value other than zero?
data want;
set t;
k=2.4;
retain k;
k+m;
run;
hi ... if you don't want to set an initial value, you can skip the RETAIN statement since a SUM statement (K+M) implies retain and starts with an initial value of 0
if you want to set an initial value ... RETAIN K 2.4;
ps http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000289454.htm
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.