BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I will appreciate if someone can explain what the following code is doing. I do not have a way to debug this.

Thanks in advance.

Code:

data bk_baddata2 (KEEP = loan_id newbaddata4 newbaddata6 newbaddata7);
set bk_baddata;
array bad(*) baddata4 baddata6 baddata7;
array new(*) newbaddata4 newbaddata6 newbaddata7;
retain newbaddata4 newbaddata6 newbaddata7;
by loan_id;
if first.loan_id then
do;
newbaddata4 = .;
newbaddata6 = .;
newbaddata7 = .;
end;
do i = 1 to 3;
if bad(i) NE . then new(i) = bad(i);
end;
if last.loan_id;
run;
4 REPLIES 4
milts
Pyrite | Level 9
Hi,

the code actually sets the value of the baddata columns equal to the newbaddata columns if the baddata does not have a null value. then the last record per loan_id is only written into the dataset bk_baddata2 along with the loan_id and newbaddata columns.

regarding the use of retain, i'm not quite sure but i think the retain part and the if first.loan_id part is redundant. no default values were set in the retain statement so the default value will be missing. i'm not sure if both are really needed.

by any chance do you know what the result table should look like?

hope this helps. if ever i explained something wrong please do correct it. thanks!

Milton
deleted_user
Not applicable
Thanks Milton, appreciate your help.

Unfortunately I do not have the result Table to match with.
deleted_user
Not applicable
One question still remains, do the following three blocks execute for every observation ?

Specially, the #2 DO loop. Does it execute for each observation?

(1) if first.loan_id then
do;
newbaddata4 = .;
newbaddata6 = .;
newbaddata7 = .;
end;

(2) do i = 1 to 3;
if bad(i) NE . then new(i) = bad(i);
end;

(3) if last.loan_id;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
It all depends on your input data - if you only have one obs per LOAN_ID, the answer is yes, otherwise #1 and #3 is NO, #2 is NO (it executes 3 times per observations, given your DO criteria.

And, why would you be asking the questions (other than a homework/quiz assignment), if you actually don't have any data to work through the discovery process with your own SAS system, input data, combined with some PUTLOG _ALL_; commands?

Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1217 views
  • 0 likes
  • 3 in conversation