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

I have the following table 

 

Year    policy_no   As_on_mar2016    As_on_Mar2015         As_on_Mar2014

2013   001                                                                                   100

2013   002                                                                                    200

2013   003                                                                                   100 

2014   001                                                    200

2014   002                                                    200                           

2014   003

2015   001                   100

2015   002                   300

2015   003                   300

 

I want the final below output like this in one variable called net_amount  from different variables above. I want As_on_Mar2014 in year 2013 against that policy, As_on_Mar2015 in 2014 and As_on_Mar2014 in 2015. Please note the policies are in tens of thousand in original data

 

Year    policy_no   Net_Amount           

2013   001                  100

2013   002                  200

2013   003                   100                                  

2014   001                  200

2014   002                  200                                                          

2014   003

2015   001                 100

2015   002                  300                                 

2015   003                  300 

 

I tried using arrays

 

data want;

set values;

arrays year (3) _temporary_ (2013 2014 2015);

arrays varf  (3)     As on Mar2014 As on Mar2015  As on Mar2016;

do i= 1 to 3;

if year =  year[i] then net amount= varf

end;

drop (i);

output;

run;

 

It does not satisfy my conditions of both year and policyno because the policies in the original data I am using is in thousands compared to year which are 5 to 6 in distinct value so how do I use the loop conditions or other methods     

 

                                               

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @sameer112217  would this help?

 

data have;
input Year    policy_no   As_on_mar2016    As_on_Mar2015         As_on_Mar2014;
cards;
2013   001               200                  .                                             100
2013   002                 .                .                                                   200
2013   003                .                           .                                        100 
2014   001                    .                                200 .
2014   002                300                              200    .                       
2014   003              .  . .
2015   001                   100 . .
2015   002                   300 . .
2015   003                   300 . .
;

data want;
set have;
array t(*) As_on_Mar2014-As_on_mar2016;
net_amt=coalesce(of t(*));
run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

 

data want;
set have;
netamt=coalesce(of As_on_mar2016--As_on_Mar2014);
run;

 

 

sameer112217
Quartz | Level 8

Thanks for the prompt reply. What if the other columns have values and we dont want to sum that. 

 

Is it possible to do array with if conditions for multiple policiy_no

 

 

novinosrin
Tourmaline | Level 20

Can you post a clear requirement and sample plz 

sameer112217
Quartz | Level 8

@novinosrin

 

I mean in the below example lets assume if there are values in other columns  like for first rows. I just want 100 in the first row values for net_amount and ignore the value 200 in the first rows. similarly in second last rows I want to ignore 300 value and take 200 since it relates with the year coalesce (of -) would sum all the rows value irrespective of the conditions if I may want to state

 

Year    policy_no   As_on_mar2016    As_on_Mar2015         As_on_Mar2014

2013   001               200                                                               100

2013   002                                                                                    200

2013   003                                                                                   100 

2014   001                                                    200

2014   002                300                              200                           

2014   003

2015   001                   100

2015   002                   300

2015   003                   300

novinosrin
Tourmaline | Level 20

Goood morning, Sorry been busy, i will respond shortly 

novinosrin
Tourmaline | Level 20

Hi @sameer112217  would this help?

 

data have;
input Year    policy_no   As_on_mar2016    As_on_Mar2015         As_on_Mar2014;
cards;
2013   001               200                  .                                             100
2013   002                 .                .                                                   200
2013   003                .                           .                                        100 
2014   001                    .                                200 .
2014   002                300                              200    .                       
2014   003              .  . .
2015   001                   100 . .
2015   002                   300 . .
2015   003                   300 . .
;

data want;
set have;
array t(*) As_on_Mar2014-As_on_mar2016;
net_amt=coalesce(of t(*));
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 2091 views
  • 1 like
  • 2 in conversation