Quartz | Level 8

## Using Arrays

I want to use two array variables . Example studname, percentage. I want to repeat the loop for 40 students and create the dataset. Pls help.
1 ACCEPTED SOLUTION

Accepted Solutions
Obsidian | Level 7

## Re: Using Arrays

```Data A ;
ARRAY studname {40} \$ studname1-studname40 ;
ARRAY percentage {40} perc1-perc40 ;
do i=1 to 40 ;
StudName[i]= 'A' || put(i,2.) ;
percentage[i]=1 + i*2 ;
end ;
run ;

Proc print ;
```

See if this helps

9 REPLIES 9
Obsidian | Level 7

## Re: Using Arrays

```Data A ;
ARRAY studname {40} \$ studname1-studname40 ;
ARRAY percentage {40} perc1-perc40 ;
do i=1 to 40 ;
StudName[i]= 'A' || put(i,2.) ;
percentage[i]=1 + i*2 ;
end ;
run ;

Proc print ;
```

See if this helps

Quartz | Level 8

## Re: Using Arrays

Thank you. Can you pls explain the program also.
Meteorite | Level 14

## Re: Using Arrays

Thanks @nrk1787db1 for the wonderful solution.
I see  that all the array elements (both for student and percentage) come in a single row.
Can we not have one row for each students.
Thus the dataset will have two columns and 40  rows instead of one row and 80 columns.
Thanks once again

Super User

## Re: Using Arrays

Can you clarify what you want?

If you just want to make a dataset with 40 students you don't normally need to use any arrays.

Quartz | Level 8

## Re: Using Arrays

I want to create dataset for 100 students and upLoad on VA for dashboard.
Super User

## Re: Using Arrays

@sas_it wrote:
I want to create dataset for 100 students and upLoad on VA for dashboard.

Normally to create a dataset you just read in the data from some source.  Such as lines of text included in the program.

``````data students;
input id age score ;
cards;
1 12 100
2 13 85
3 14 78
;``````

If you want to make up example data you can use a DO loop with an OUTPUT statement to write multiple observations.

``````data students;
do id=1 to 100;
output;
end;
run;``````

Again arrays really do not come into play here.  Arrays are for when you have multiple variables that contain similar data and you want to loop over them (or index into them).

Meteorite | Level 14

## Re: Using Arrays

Thanks @Tom
I have the arrays and the specific example of @nrk1787db1 in mind.

Super User

## Re: Using Arrays

@Sajid01 wrote:

Thanks @Tom
I have the arrays and the specific example of @nrk1787db1 in mind.

Again no arrays needed.

``````data students;
length name \$8 percent 8;
do i=1 to 40;
name = cats('A',put(i,z2.));
percent=1 + 2*i ;
output;
end;
drop i;
run;``````

Results:

Quartz | Level 8

## Re: Using Arrays

Thank you.
Discussion stats
• 9 replies
• 880 views
• 4 likes
• 4 in conversation