@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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.