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

Hello everyone,

 

I would like to ask the question as below,

and I have searched for the definition of multi array,

but I still cannot relate to this question.

Any help would be highly appreciated.

 

multi array
array multi{1:2, 2} (1,2);
do i=1 to 2;
do j=1 to 2;
Output=multi{i,j};

The question is:

What is the corresponding values of i, j and output?

 

The answer is 1,1,1

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Is there any reason you're not running this and checking it?

 

Anyways, the answer is wrong, it's 1, 2. 

 

A multi array is row by column, so you've specified 1:2, 2 -> which is 2x2 and 4 entries. You've only initialized the first two values, as 1 and 2. 

Here's the code for you to run. 

 

 

data have;
    array multi{1:2, 2} (1, 2);

    do i=1 to 2;

        do j=1 to 2;
            Output=multi{i, j};
            output;
        end;
    end;
run;

proc print data=have;
run;

And here's the documentation reference - it's fairly detailed and thorough in my opinion. 

 

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0e7601ugjmfgan1vysixzg3a71j.htm&docsetVe...

 


@jc3992 wrote:

Hello everyone,

 

I would like to ask the question as below,

and I have searched for the definition of multi array,

but I still cannot relate to this question.

Any help would be highly appreciated.

 

multi array
array multi{1:2, 2} (1,2);
do i=1 to 2;
do j=1 to 2;
Output=multi{i,j};

The question is:

What is the corresponding values of i, j and output?

 

The answer is 1,1,1

 

 


 

View solution in original post

4 REPLIES 4
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

the code you have provided will not output because you have missing end statements for 2 of your do loops;

Depending on your end statements will have an impact on the output.

Reeza
Super User

Is there any reason you're not running this and checking it?

 

Anyways, the answer is wrong, it's 1, 2. 

 

A multi array is row by column, so you've specified 1:2, 2 -> which is 2x2 and 4 entries. You've only initialized the first two values, as 1 and 2. 

Here's the code for you to run. 

 

 

data have;
    array multi{1:2, 2} (1, 2);

    do i=1 to 2;

        do j=1 to 2;
            Output=multi{i, j};
            output;
        end;
    end;
run;

proc print data=have;
run;

And here's the documentation reference - it's fairly detailed and thorough in my opinion. 

 

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0e7601ugjmfgan1vysixzg3a71j.htm&docsetVe...

 


@jc3992 wrote:

Hello everyone,

 

I would like to ask the question as below,

and I have searched for the definition of multi array,

but I still cannot relate to this question.

Any help would be highly appreciated.

 

multi array
array multi{1:2, 2} (1,2);
do i=1 to 2;
do j=1 to 2;
Output=multi{i,j};

The question is:

What is the corresponding values of i, j and output?

 

The answer is 1,1,1

 

 


 

jc3992
Pyrite | Level 9

Thank you!

Yes, I have checked that documentation too.

But I do not fully understand what it is doing and I am not sure about the code I can write to run it.

I am confused what that (1,2) meant.

Thank you very much!!

Reeza
Super User

ARRAY array-name {number-of-elements} <$> <length> <array-elements> <(initial-value-list)>;

 

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p19dovt76d4zv4n1h91lg4i12mmm.htm&docsetVe...

 

 

Whenever you can't understand specific syntax, find the syntax definition in the documentation. It lists the items in the order and you can match them up to figure out what each term means. 

 


@jc3992 wrote:

Thank you!

Yes, I have checked that documentation too.

But I do not fully understand what it is doing and I am not sure about the code I can write to run it.

I am confused what that (1,2) meant.

Thank you very much!!


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1428 views
  • 0 likes
  • 3 in conversation