Help using Base SAS procedures

array problem

Accepted Solution Solved
Reply
Regular Contributor
Posts: 229
Accepted Solution

array problem

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


Accepted Solutions
Solution
‎04-04-2015 02:29 PM
Regular Contributor
Posts: 229

Re: array problem

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


All Replies
Trusted Advisor
Posts: 1,137

Re: array problem

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
Super User
Posts: 7,092

Re: array problem

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;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Respected Advisor
Posts: 3,780

Re: array problem

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
Solution
‎04-04-2015 02:29 PM
Regular Contributor
Posts: 229

Re: array problem

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 267 views
  • 3 likes
  • 4 in conversation