The number of elements in the array cannot change from one observation to the next. If the length of an account number can vary from one observation to the next, you need to define an array with enough elements to hold the longest account number.
Here's a small change that can end your DO loop once all the characters are read from ACCNO:
if finda > 0 then do i=1 to (length(line) - finda + 1);
Also note, your array statement is defining name1-name12 as being 8 characters long. A simple change can fix that:
array namea (12) $ 1 name1-name12;
Hi all,
I need some help on the below code.
I wanted to Split the the account numbers , But as the i coun not make the array dynamic and it is creating additional columns.I wanted name1-Name12 should stop when finda gets the maximum value.Can i create array as per the number which produce by finda . finda is a user variable. could be anything.
data newdata;
input Line$ 30.;
finda = anydigit(Line);
if finda > 0 then
accno = substr(Line,finda,10 ) ;
Array namea (12)$ name1-Name12;
do i = 1 to 12;
namea (i)= Substr(accno ,i,1);
end;
datalines;
Citi 2323232
State Bank of india 232323
;
proc print data = newdata;
run;
@pearsoninst, you have posted your question in the discussion forum that is not about SAS products (this is the discussion board to discuss the new community platform).
I need to move your post to another community.. If you could please click the orange Find a Community box in the right nav and advise which community you think this belongs and I'm happy to move it for you...
Otherwise I can move it to Base SAS Programming (https://communities.sas.com/t5/Base-SAS-Programming/bd-p/programming)
Thanks!! I say this because you will find people will respond more quickly to the topical discussion forums as they are probably not following this forum as closely..
Why do you want to split up the account numbers into single digits? If you let us know then may be there are other ways to achieve your desired end result.
Hi @pearsoninst, no worries ! 😉
I will move this post to the programming community forum -- I follow this forum very closely but I'm not a SAS expert 🙂
Take care,
Lainie
The number of elements in the array cannot change from one observation to the next. If the length of an account number can vary from one observation to the next, you need to define an array with enough elements to hold the longest account number.
Here's a small change that can end your DO loop once all the characters are read from ACCNO:
if finda > 0 then do i=1 to (length(line) - finda + 1);
Also note, your array statement is defining name1-name12 as being 8 characters long. A simple change can fix that:
array namea (12) $ 1 name1-name12;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.