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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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