Solved
Contributor
Posts: 29

# Controlling Variable Suffix by Creating New Variables with an Array

[ Edited ]

Hi,

I'm trying to create new variables with an array statement that contain suffixes that match from a previously referenced array statement. This is my code:

```DATA BLAH_F7;
SET BLAH_F;
ARRAY A[0:100]F_0--F_100;
ARRAY P_[0:100]P_0--P_100;
DO I=0 TO 100;
P_(I)=A(I)/F_TOTAL;
END;
DROP I;
RUN;```

When I run this code, the array creates variables P_1 to P_101 instead of from P_0 to P_100, which is what I want (as I am trying to match to the F_0 to F_100 variables). Anyone have any suggestions? If this isn't possible using an array statement, I'd still be interested in hearing the simplest way to change these P_1 to P_101 variables to P_0 to P_100.

Thanks.

Accepted Solutions
Solution
‎07-26-2016 11:44 AM
Super User
Posts: 23,773

## Re: Controlling Variable Suffix by Creating New Variables with an Array

Try the following, though I would have thought that P0-P100 would work.

Array p_(0:100) p0 p1-p100;

All Replies
Solution
‎07-26-2016 11:44 AM
Super User
Posts: 23,773

## Re: Controlling Variable Suffix by Creating New Variables with an Array

Try the following, though I would have thought that P0-P100 would work.

Array p_(0:100) p0 p1-p100;

Contributor
Posts: 29

## Re: Controlling Variable Suffix by Creating New Variables with an Array

Thanks, this solution works. I guess P_0 needs to be explicitly stated since this is an array statement that isn't referencing any previously exisiting variables? I'm a little confused by why this works:

Array p_(0:100) p0 p1-p100;

but this doesn't work:

Array p_(0:100) p0-p100;

Super User
Posts: 6,785

## Re: Controlling Variable Suffix by Creating New Variables with an Array

Both of those should work.

The piece that doesn't work is the double dash.  For SAS to interpret the double dash properly, the variables must already exist and cannot be created by the ARRAY statement.

Contributor
Posts: 29