BookmarkSubscribeRSS Feed
wendy_sasuser
Calcite | Level 5

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.

1 REPLY 1
Linlin
Lapis Lazuli | Level 10

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

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1302 views
  • 0 likes
  • 2 in conversation