Hello
can we use the dim function to define the size of vector in a macro ?
Thank you
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(¯o_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.
Yes, you can put any data step command and any function in a macro.
Macros are just text substitution ... instead of %macroname or ¯ovariablename, 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.
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(¯o_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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.