@ponder wrote:
Dear all,
I have a data with columnnames column_1 to column_n and i want to create an array out of the columns. n is dynamic.
what i have in mind is
%let i=5;
data x;
set y;
array var column1-column&i;
run;
But it does not work. Any suggestion is highly appraciated.
Thanks
Here is a reference that illustrates how to refer to variables and datasets in a short cut list. Using a list lets you avoid using macros.
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
array var(*) column: ;
*this will take all column names that start with column;
Hi @ponder ,
It seems that you have a mispelling in the column name (missing underscore).
Could you please test this code and tell us if the issue persists? (please do not hesitate to share the error message)
Best,
data x;
set y;
array var(*) column_1-column_&i;
run;
"does not work" on its own is awfully vague and tells us next to nothing. If you have (a) problem(s), post the log, and if you get results that do not meet your expectations, post example data, the result, and what you expected.
@ponder wrote:
Dear all,
I have a data with columnnames column_1 to column_n and i want to create an array out of the columns. n is dynamic.
what i have in mind is
%let i=5;
data x;
set y;
array var column1-column&i;
run;
But it does not work. Any suggestion is highly appraciated.
Thanks
Here is a reference that illustrates how to refer to variables and datasets in a short cut list. Using a list lets you avoid using macros.
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
array var(*) column: ;
*this will take all column names that start with column;
Thanks! That solved my problem.
For the next time i will provide more information about the problem
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.