Hello everyone,below is my SAS code that cause error: "ERROR: Missing numeric suffix on a numbered variable list (b_1-b_dim)".
Please advise.
data test;
set sasuser.class;
array one(*) _CHARACTER_ ;
/*I want array two have same dimension as array one,but i can't*/
array two(*) b_1-b_dim(one);
run;
Thanks!
George
You cannot do that. You could make it a two step process using a macro variable to remember the information from the first step.
data _null_;
set sasuser.class;
array one(*) _CHARACTER_ ;
call symputx('DIM',dim(one);
stop;
run;
data test;
set sasuser.class;
array one(*) _CHARACTER_ ;
/*I want array two have same dimension as array one,but i can't*/
array b_ (&dim) ;
run;
hi,
Post some test data of have and want. Your code will not work as is, i.e. first off array one is not assigned anything, in the second array dim() does not de-reference like a macro variable.
You cannot do that. You could make it a two step process using a macro variable to remember the information from the first step.
data _null_;
set sasuser.class;
array one(*) _CHARACTER_ ;
call symputx('DIM',dim(one);
stop;
run;
data test;
set sasuser.class;
array one(*) _CHARACTER_ ;
/*I want array two have same dimension as array one,but i can't*/
array b_ (&dim) ;
run;
The answer to your question is more complex than you might imagine. First, here are the principles involved.
The DATA step operates in two phases. First, the software checks through all your DATA step statements, checks for syntax errors, and performs the set-up work (such as setting up storage locations for each variable). Once that is complete, it enters the second phase, which is actually executing your statements.
The DIM function executes in phase 2, when all the DATA step statements are executing. But the software needs to know how many elements are in the array as part of phase 1 (set-up). So the DIM function doesn't execute in time, generating the error in phase 1.
The solution is not particularly lengthy. Set up an initial DATA step to capture the number of elements in the array, then use that number later. For example:
data _null_;
set sasuser.class;
array one{*} _character_;
call symputx('n_cvars', dim(one));
stop;
run;
Then in the second DATA step:
array two {&n_cvars} b_1 - b_&n_cvars;
Hope this is clear enough. Good luck.
Tom, you're fast. Looks like great minds think alike.
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.