BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GeorgeSAS
Lapis Lazuli | Level 10

Hello everyone,

Can you help me find the problem? I want b as new variable and have same dimension as a

data one;

set sashelp.class;

array a _character_;

array b(*) b1-b(dim(a));

for i-1 to dim(a);

b=a;

end;

run;

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
GeorgeSAS
Lapis Lazuli | Level 10

data _null_;

   if 0 then set sashelp.class(keep=_character_);

   array a _character_;

   call symputX('array_size',dim(a));

   stop;

   run;

data one;

set sashelp.class;

array a _character_;

array b(*) $ b1-b&array_size.;

do i=1 to dim(a);

b=a;

end;

run;

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Please try

data one;

set sashelp.class;

array a(*) _character_ ;

array b(*) $ b1-b2;

do i = 1 to dim(a);

b=a;

end;

run;

Thanks,

Jag

Thanks,
Jag
Kurt_Bremser
Super User

You can't use dim() to define an array. The array elements are determined at compile time, while dim() is a function resolved at runtime of the data step.

Store the array size into a macro variable and use that:

data _null_;

set sashelp.class;

if _n_ = 1;

array a _character_;

call symput('array_size',left(trim(put(dim(a),best4.))));

run;

data one;

set sashelp.class;

array a _character_;

array b(*) $ b1-b&array_size;

do i = 1 to dim(a);

b=a;

end;

run;

data_null__
Jade | Level 19

You don't need to read any records and certainly not ALL of them.

data _null_;
  
if 0 then set sashelp.class(keep=_character_);
   array a _character_;
  
call symputX('array_size',dim(a));
   stop;
  
run;
%put NOTE: &=array_size;


NOTE:
ARRAY_SIZE=2
GeorgeSAS
Lapis Lazuli | Level 10

data _null_;

   if 0 then set sashelp.class(keep=_character_);

   array a _character_;

   call symputX('array_size',dim(a));

   stop;

   run;

data one;

set sashelp.class;

array a _character_;

array b(*) $ b1-b&array_size.;

do i=1 to dim(a);

b=a;

end;

run;

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
  • 4 replies
  • 1767 views
  • 3 likes
  • 4 in conversation