BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GeorgeSAS
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Tom
Super User Tom
Super User

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;

Astounding
PROC Star

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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