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

Hello

can we use the dim function  to define the size of vector in a macro ?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

No.  The DIM function applies to DATA step arrays only.

 

However, you can use the COUNTW function, as long as you apply %SYSFUNC:

 

%do k=1 to %sysfunc(countw(&macro_list));

 

There are only mild restrictions.  Be sure that your macro variable isn't null, and the same delimiter must be used to separate all values within the macro variable.

 

In retrospect, it looks like @PaigeMiller and I interpreted your question differently.  You may need to give a little more description on what you are trying to achieve.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Yes, you can put any data step command and any function in a macro.

 

Macros are just text substitution ... instead of %macroname or &macrovariablename, code is substituted depending on the value of the macro or the value of the macro variable, so when this code substitution happens, you must wind up with legal valid (not erroneous) SAS code.

--
Paige Miller
Astounding
PROC Star

No.  The DIM function applies to DATA step arrays only.

 

However, you can use the COUNTW function, as long as you apply %SYSFUNC:

 

%do k=1 to %sysfunc(countw(&macro_list));

 

There are only mild restrictions.  Be sure that your macro variable isn't null, and the same delimiter must be used to separate all values within the macro variable.

 

In retrospect, it looks like @PaigeMiller and I interpreted your question differently.  You may need to give a little more description on what you are trying to achieve.

Kurt_Bremser
Super User

Dim() is a function that expects an array as argument. Since arrays exist only in data steps, you cannot use them outside.

If you want to record the size of an array, use call symput() in a data step:

data _null_;
set have;
array myvars {*} var:;
call symputx('dim',dim(myvars));
stop;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2737 views
  • 0 likes
  • 4 in conversation