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;
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
Try this:
flow{input(cycle_delq,1.) - 1} = CURRENT_DLQ_AMT;
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
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: