my $last_4_chars = '0001'; my @all_stores = map { # This sas file will seperate the datasets by stores # Opens file to write to open my $fh, '>', "weekly_${_}_pdf.sas" or die "Cannot open weekly_${_}_pdf.sas: $!"; [ $_, $fh ] } qw( 24 25 ); for my $store ( @all_stores ) { print { $store->[ 1 ] } <= 1.2 then 'G' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) <= 1.2 and (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= .65 then 'Y' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) < .65 then 'R' end) as WTD_Color MTDTRAN,MTDOFFERS,MTDAPPS, substr(MTDOFFERS/MTDAPPS,0,5) as MTD_RATE, (case when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= 1.2 then 'G' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) <= 1.2 and (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= .65 then 'Y' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) < .65 then 'R' end) as MTD_Color FROM bce.yearly_g${last_4_chars}v00 WHERE RPTSTORE = $store->[0] Order by RPTTEAM STORE } close $_->[ 1 ] for @all_stores;