BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sampath
Calcite | Level 5

Hi,

I am wondering if it is possible to create elements in arrays. I have the following code. I believe _1 _2 _0 are created in this step. Also I am wondering whether "do over col" is same as  "do i = 1 to dim(col);

Could you please clarify.

data den;

   set den ;

  array col _1 _2 _0 _99 _999;

  do over col;

    if col=. then col=0;

  end;

run;

Thanks,

Sam.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

With a slight modification of your code you can see that the answers are both yes .. sort of.  First, try the following:

data den;

  array col _1 _2 _0 _99 _999;

  do over col;

    counter+1;

    col=counter;

  end;

run;

As you can see after running the code, the five variables do indeed get created, and their assignments in the do over loop are clearly sequential.

I say "sort of" though, as you can only use do over with an implicitly defined array (i.e., where you don't define the number of elements in brackets in the array declaration) and, with implicitly defined arrays, you can't refer to them by number (e.g., col(1)).

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

With a slight modification of your code you can see that the answers are both yes .. sort of.  First, try the following:

data den;

  array col _1 _2 _0 _99 _999;

  do over col;

    counter+1;

    col=counter;

  end;

run;

As you can see after running the code, the five variables do indeed get created, and their assignments in the do over loop are clearly sequential.

I say "sort of" though, as you can only use do over with an implicitly defined array (i.e., where you don't define the number of elements in brackets in the array declaration) and, with implicitly defined arrays, you can't refer to them by number (e.g., col(1)).

sampath
Calcite | Level 5

I understood clearly. Thank you very much Arthur.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 768 views
  • 4 likes
  • 2 in conversation