## Create group variable in array by interval

Solved
Super Contributor
Posts: 383

# Create group variable in array by interval

Hi y'all,

Please help create a group variable risk [i] in data step to my existing set of dataset.

where:

median of data is 300

risk[1]=300/3

risk[last]=300*3

by interval of 10.

The range has to be 300/3-300*3 with median of 300.

``````data temp; set agerisk;
array risk {i};
do i=1 to dim[risk];
...
end;
run;``````

Accepted Solutions
Solution
‎02-09-2018 01:18 PM
Super User
Posts: 13,941

## Re: Create group variable in array by interval

Cruise wrote:
Thanks a lot for getting back to me. I want:
risk val
1 100
2 200
3 300
4 400
5 500
6 600
7 700
8 800
9 900
10 1000
11 1100
12 1200
13 1300
14 1400
15 1500

That looks like you want to create a val as 100* risk. Which would be:

```data want;
do risk=1 to 15;
val = Risk*100;
output;
end;
run;```

All Replies
Super Contributor
Posts: 383

## Re: Create group variable in array by interval

What am i doing wrong here? I simply want two variables created to the same number of rows in a new dataset?

``````data c.temp;
do risk=1 to 15 by 1;
do val=100 to 1500 by 100;
end;
end;
output;
run; ``````
Super User
Posts: 13,941

## Re: Create group variable in array by interval

Cruise wrote:

What am i doing wrong here? I simply want two variables created to the same number of rows in a new dataset?

``````data c.temp;
do risk=1 to 15 by 1;
do val=100 to 1500 by 100;
end;
end;
output;
run; ``````

Hard to tell what you  are doing wrong with out knowing what the output should look like.

But if you want output for each iteration the OUTPUT has to be inside one of the loops. likely

```data c.temp;
do risk=1 to 15 by 1;
do val=100 to 1500 by 100;
output;
end;
end;
run; ```
Super Contributor
Posts: 383

## Re: Create group variable in array by interval

Thanks a lot for getting back to me. I want:
risk val
1 100
2 200
3 300
4 400
5 500
6 600
7 700
8 800
9 900
10 1000
11 1100
12 1200
13 1300
14 1400
15 1500
Solution
‎02-09-2018 01:18 PM
Super User
Posts: 13,941

## Re: Create group variable in array by interval

Cruise wrote:
Thanks a lot for getting back to me. I want:
risk val
1 100
2 200
3 300
4 400
5 500
6 600
7 700
8 800
9 900
10 1000
11 1100
12 1200
13 1300
14 1400
15 1500

That looks like you want to create a val as 100* risk. Which would be:

```data want;
do risk=1 to 15;
val = Risk*100;
output;
end;
run;```
☑ This topic is solved.