BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi. I would like to initialise my array by assigning each element with a zero value. I can do this through a do loop but I thought that I could do something neater / better by doing something like this:

Array Var{5} (0 0 0 0 0);
or Array Var{5} (5*0); ??

but this seems to make the array possess some sort of RETAIN feature which is not what I want. Any ideas?
2 REPLIES 2
LinusH
Tourmaline | Level 20
From on-line doc:
"When any (or all) elements are assigned initial values, all elements behave as if they were named on a RETAIN statement."

In this case, it would nice to say something like:

var{*} = 0;

but you can't. So I guess you are stuck with doing a do loop.

/Linus
Data never sleeps
data_null__
Jade | Level 19
I have had some success with this using SET with the POINT= option.

This example is completely contrived but it may serve well enough to illustrate a way to initialize a list of variables without looping over all the elements of an array.

[pre]
data initArray;
array v[5];
retain v 0;
run;
data workWithArray;
array v[5];
do i = 1 to 6;
if i in(1,2,4) then set initArray point=point;
else do j = 1 to dim(v);
v = ranuni(1);
end;
output;
end;
retain point 1;
stop;
run;
proc print;
run;
[pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 746 views
  • 0 likes
  • 3 in conversation