DATA Step, Macro, Functions and more

Array without knowing it size

Reply
User
Posts: 1

Array without knowing it size

Hello SAS users,

 

After looking and looking, I can't find an efficient solution. My problem is I have to stay in a one and unique dataset.

The length of the array will change so it cannot be a number define.

 

The length of the array always be length1.

 

The only solution I found it's define a big number to have my 11 new variables.

Please find an example of code below:

 

data test ;
length1=11;
array psc00013_trans_amount{0:99999} 3.;
do i=1 to length1;
psc00013_trans_amount{i} = 0 ;
end;
run;

 

Thanks for your help, I'm totally lost.

Super User
Posts: 10,500

Re: Array without knowing it size


alorenzo wrote:

Hello SAS users,

 

After looking and looking, I can't find an efficient solution. My problem is I have to stay in a one and unique dataset.

The length of the array will change so it cannot be a number define.

 

The length of the array always be length1.

 


You need to clarify what you mean by those two statments. Where does the value for length1 come from?

Is the purpose of this exercise to make a data set with one row of data of a specified number of variables all with value 0?

 

You may also be able to set the definition of the values to 0 at creation without the do loop.

 

Note that since you have set the lower bound on your array as 0 in the definition then the loop going from 1 to length1 will not assign a value to the zero element.

 

 

Super User
Posts: 9,681

Re: Array without knowing it size

You can grab that magic number ,and apply it into ARRAY.

%let dsid=%sysfunc(open(sashelp.class));
%let nvar=%sysfunc(attrn(&dsid,nvars));
%let dsid=%sysfunc(close(&dsid));

%put &nvar ;

Ask a Question
Discussion stats
  • 2 replies
  • 192 views
  • 0 likes
  • 3 in conversation