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
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;
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
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;
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;
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.