Solved
Valued Guide
Posts: 864

# use value to populate new variable

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.

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;

Accepted Solutions
Solution
‎01-09-2018 01:07 PM
Super User
Posts: 2,061

## Re: use value to populate new variable

[ Edited ]

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

All Replies
Super User
Posts: 10,571

## Re: use value to populate new variable

Try this:

`` flow{input(cycle_delq,1.) - 1} = CURRENT_DLQ_AMT;``
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎01-09-2018 01:07 PM
Super User
Posts: 2,061

## Re: use value to populate new variable

[ Edited ]

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

Valued Guide
Posts: 864

## Re: use value to populate new variable

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;

☑ This topic is solved.