BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pearsoninst
Pyrite | Level 9
Hi LainieH,
Very Sorry , i think this is the 2nd time i did this .I dont know how i forgot ? . I will remember . Thank you . Kanchan
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

  

View solution in original post

5 REPLIES 5
pearsoninst
Pyrite | Level 9

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;

LainieH
Community Manager

@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..

 

 

Patrick
Opal | Level 21

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. 

LainieH
Community Manager

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

Astounding
PROC Star

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;

  

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
  • 5 replies
  • 938 views
  • 1 like
  • 4 in conversation