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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 2485 views
  • 0 likes
  • 4 in conversation