BookmarkSubscribeRSS Feed
hcnyl2018
Calcite | Level 5

Input data file have month-end value for each account, I need to covert to tenureship value, meaning value as of month 1, month 2, ... month n, with month 1 starting from the open_month:

 

Here is the input file "Book1":

account_idOpen_monthvalue_1611vale_1612value_1701value_1702value_1703value_1704value_1705value_1706value_1707value_1708value_1709value_1710value_1711value_1712value_1801
10034Aug-1700000000011522502383315333773488
11005May-17000000551550556548558567582604622
11008Feb-17000534453275295529350174938494049174101404722992302
32057Nov-161080107110641055104710381030102200037373838
32066Oct-170000000000049776581008391
99971Mar-17000030223017930843252239119881566163922542594

 

Desired output:

account_idOpen_monthvalue_month0value_month1value_month2value_month3value_month4value_month5value_month6value_month7value_month8value_month9value_month10value_month11value_month12value_month13value_month14
10034Aug-1711522502383315333773488---------
11005May-17551550556548558567582604622000000
11008Feb-17534453275295529350174938494049174101404722992302000
32057Nov-161080107110641055104710381030102200037373838
32066Oct-174977658100839100000000000
99971Mar-1730223017930843252239119881566163922542594000

0

 

 

This is my code, but returned error (it worked if the date sequence is consecutive, like 1701-1715, but no longer works when I have 1611, 1612, 1801 in the mix with 1701-1712), the error returned says:

ERROR: Too many variables defined for the dimension(s) specified for the array bal.

 

data transform_bal;

set book1;

array bal(15) value_1611-value_1801;

array val(15) value_month0-value_month14;

length name1 $ 32;

n=0;

do i=1 to 15;

call vname(bal(i),name1);

if input(scan(name1,2,'_'),4.)=open_month then flag=1;

if flag=1 then do;

n+1;

 

val(n)=bal(i);

end;

end;

drop value_1611-value_1801 name1 i n flag;

run;

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

You have to list the 15 variables if they are not numbered consecutively:

 

 

array bal(15) value_1611 value_1612 value_1801 etc ;

hcnyl2018
Calcite | Level 5

Thank you, ChrisNZ! problem solved, can't believe it's that simple, lol

FreelanceReinh
Jade | Level 19

You can use what is called a name range list (see documentation😞

 

value_1611--value_1801

(assuming that this reflects the order of the variables in dataset Book1). This would even cope with a mistyped name like your "vale_1612".

 

 

It's not clear from what you've shown that this IF condition will work:

 

input(scan(name1,2,'_'),4.)=open_month

It would require that variable Open_month contains numeric values like 1708 rather than SAS date values or character values like 'Aug-17'.

 

Also, I'm wondering if you need this wide dataset only for reporting purposes because otherwise a long format would be much more convenient (e.g. when it comes to updating the table with months 1802, 1803 etc.).

 

 

 

hcnyl2018
Calcite | Level 5

Thank you so much, FreelanceReinhard!

value_1611--value_1801 worked! Just one more hyphen, it's that simple!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1108 views
  • 1 like
  • 3 in conversation