BookmarkSubscribeRSS Feed
alorenzo
Calcite | Level 5

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.

2 REPLIES 2
ballardw
Super User

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

 

 

Ksharp
Super User
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 ;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 1724 views
  • 0 likes
  • 3 in conversation