Help using Base SAS procedures

Using array and order, no error messages, but output is strange

Reply
N/A
Posts: 1

Using array and order, no error messages, but output is strange

Hello,

I am doing a simple array procedure to shape a series of wide variables into one long variable. The interesting variable is obtn1, obtn2, obtn3, obtn4, obtn5. After I run the following codes, I got a dataset with a new variable "order=6" for all observations. I have no idea where the '6' came from.

And the new variable obt is almost all " . " even when the original obtn1-obtn5 were quite well filled. Anyone knows what happened here? 

Thanks!

data all_year2;

set all_year;

array obt [5] OBTN1 OBTN2 OBTN3 OBTN4 OBTN5;

do order=1 to 5;

obtain=obt [order];

end;

run;

obtn1-obtn5 are numerical variables.

Super Contributor
Posts: 1,636

Using array and order, no error messages, but output is strange

you need an output statement. try the code below:

data all_year;

input OBTN1 OBTN2 OBTN3 OBTN4 OBTN5;

cards;

1 2 3 4 5

6 7 8 9 10

;

data all_year2;

set all_year;

array obt [5] OBTN1 OBTN2 OBTN3 OBTN4 OBTN5;

do order=1 to 5;

obtain=obt [order];

output;

end;

run;

proc print;run;

Linlin

Ask a Question
Discussion stats
  • 1 reply
  • 537 views
  • 0 likes
  • 2 in conversation