turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Array without knowing it size

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-07-2016 12:04 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-07-2016 12:17 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-08-2016 07:08 AM

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 ;