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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1170 views
  • 0 likes
  • 3 in conversation