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
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
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
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.
@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).
Thanks @Tom
I have the arrays and the specific example of @nrk1787db1 in mind.
@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:
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.