Help using Base SAS procedures

question about array

Accepted Solution Solved
Reply
Regular Contributor
Posts: 241
Accepted Solution

question about array

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


Accepted Solutions
Solution
‎03-24-2015 11:46 AM
Super User
Super User
Posts: 7,060

Re: question about array

Posted in reply to GeorgeSAS

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;

View solution in original post


All Replies
Super User
Super User
Posts: 7,970

Re: question about array

Posted in reply to GeorgeSAS

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.

Solution
‎03-24-2015 11:46 AM
Super User
Super User
Posts: 7,060

Re: question about array

Posted in reply to GeorgeSAS

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;

Super User
Posts: 5,513

Re: question about array

Posted in reply to GeorgeSAS

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.

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 235 views
  • 6 likes
  • 4 in conversation