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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.