BookmarkSubscribeRSS Feed
ZRick
Obsidian | Level 7

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

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

data t;

input m;

cards;

5

4

11

;

data want;

  set t;

  retain k;

  k+m;

run;

proc print;run;

Linlin

ZRick
Obsidian | Level 7

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;

MikeZdeb
Rhodochrosite | Level 12

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1419 views
  • 0 likes
  • 3 in conversation