DATA Step, Macro, Functions and more

How to create n number of arrays.

Reply
New Contributor
Posts: 3

How to create n number of arrays.

Hi,

I have a string, Let it be 'GOOD'. Now I want to create a array with the length of the string i.e 4(here length of the string GOOD is 4). And I want to take each character of GOOD into each array element and I want to concatenate all the four array elements. Finally the result would be GOOD only.

New Contributor
Posts: 3

Re: How to create n number of arrays.

Posted in reply to K_HARI_PRASAD

Here the length may vary each time that is instead of GOOD i may pass THIS IS SAS

Respected Advisor
Posts: 3,799

Re: How to create n number of arrays.

Posted in reply to K_HARI_PRASAD

In SAS arrays have fixed length defined when the code is compiled.  The associative array (hash) is a dynamic sized object so you may consider that option.

However I don't see the point of your question.  State the problem again in more detail.

While you do that you may consider this bit

data test;
   input string $char20.;
  
array c[20] $1;
  
call pokelong(string,addrlong(c[1]),length(string));
   *CALL POKELONG(source,pointer<,length><,floating-point> );
  
cards;
GOOD
i may pass
THIS IS SAS
;;;;
   run;
proc print;
  
run;
Super User
Posts: 11,343

Re: How to create n number of arrays.

Posted in reply to K_HARI_PRASAD

Provide some input/output examples.

Pulling individual characters and then concatenating them back to a string really sounds like you may be needing one of Strip, Compress or some other string function instead.

Ask a Question
Discussion stats
  • 3 replies
  • 349 views
  • 1 like
  • 3 in conversation