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

I think an array will solve this problem but I'm not very experienced using them.  I have one field delinquent count, I would like to use that field to assign a value to another field.  If delinquent count is 3, then the value of delinquent amount should go into d_cycle3.  Below is some code that will show what I am trying to do.  I've been playing around with arrays trying to get it done with no success.

 

Thanks in advance. 

 

If there's a better way than an array I'm open to that too.

 

Cheers,

 

data have;
infile cards;
input id$ cycle_delq$ CURRENT_DLQ_AMT;
cards;
001 0 0
001 0 0
001 1 5
001 1 5
001 2 10
001 3 10
001 4 15
001 4 15
001 5 20
001 C 0
;
run;

data want;
set have;
array flow{6} d_cycle0-d_cycle5;
if input(cycle_delq,1.) = 0 then d_cycle0 = CURRENT_DLQ_AMT;
if input(cycle_delq,1.) = 1 then d_cycle1 = CURRENT_DLQ_AMT;
if input(cycle_delq,1.) = 2 then d_cycle2 = CURRENT_DLQ_AMT;
if input(cycle_delq,1.) = 3 then d_cycle3 = CURRENT_DLQ_AMT;
if input(cycle_delq,1.) = 4 then d_cycle4 = CURRENT_DLQ_AMT;
if input(cycle_delq,1.) = 5 then d_cycle5 = CURRENT_DLQ_AMT;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data wantt;
set have1;
array flow{0:5} d_cycle0-d_cycle5;
temp=input(cycle_delq,1.);
flow(temp)=CURRENT_DLQ_AMT;

drop temp;

run;

 

EDITED: To add drop temp statement

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

data wantt;
set have1;
array flow{0:5} d_cycle0-d_cycle5;
temp=input(cycle_delq,1.);
flow(temp)=CURRENT_DLQ_AMT;

drop temp;

run;

 

EDITED: To add drop temp statement

Steelers_In_DC
Barite | Level 11

That was close, thanks so much.  Because of the potential for Character values there is one more step needed:

 

data want;
set have;
array flow{0:5} d_cycle0-d_cycle5;
if not missing(input(cycle_delq,1.)) then do;
temp=input(cycle_delq,1.);
flow(temp)=CURRENT_DLQ_AMT;
end;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1736 views
  • 0 likes
  • 3 in conversation