BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

Is the below an Issue or my lack of understanding: Sum statement with RETAIN vs NO RETAIN handling missing values



data _null_;
  retain k;
  b=.;
  k+b;
  put k=;
run;


data _null_;
/*  retain k;*/
  b=.;
  k+b;
  put k=;
run;

Can somebody explain and help me why the difference in the results of K in the above 2 programs plz? Thank you in advance! 

 

LOG-


70
71   data _null_;
72     retain k;
73     b=.;
74     k+b;
75     put k=;
76   run;

k=.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


77
78
79   data _null_;
80   /*  retain k;*/
81     b=.;
82     k+b;
83     put k=;
84   run;

k=0
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

@novinosrin wrote:

Is the below an Issue or my lack of understanding: Sum statement with RETAIN vs NO RETAIN handling missing values



data _null_;
  retain k;
  b=.;
  k+b;
  put k=;
run;


data _null_;
/*  retain k;*/
  b=.;
  k+b;
  put k=;
run;

Can somebody explain and help me why the difference in the results of K in the above 2 programs plz? Thank you in advance! 

 

LOG-


70
71   data _null_;
72     retain k;
73     b=.;
74     k+b;
75     put k=;
76   run;

k=.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


77
78
79   data _null_;
80   /*  retain k;*/
81     b=.;
82     k+b;
83     put k=;
84   run;

k=0
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 


In your first data step you RETAIN K and implicitly initialize to missing.

Screenshot 2021-09-10 102646.png

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

@novinosrin wrote:

Is the below an Issue or my lack of understanding: Sum statement with RETAIN vs NO RETAIN handling missing values



data _null_;
  retain k;
  b=.;
  k+b;
  put k=;
run;


data _null_;
/*  retain k;*/
  b=.;
  k+b;
  put k=;
run;

Can somebody explain and help me why the difference in the results of K in the above 2 programs plz? Thank you in advance! 

 

LOG-


70
71   data _null_;
72     retain k;
73     b=.;
74     k+b;
75     put k=;
76   run;

k=.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


77
78
79   data _null_;
80   /*  retain k;*/
81     b=.;
82     k+b;
83     put k=;
84   run;

k=0
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 


In your first data step you RETAIN K and implicitly initialize to missing.

Screenshot 2021-09-10 102646.png

Ksharp
Super User
Sum statement include another implicated statement (i.e. retain k 0 😉

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 729 views
  • 2 likes
  • 3 in conversation