BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ponder
Calcite | Level 5
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
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@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;

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

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;

 

 

Kurt_Bremser
Super User

"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.

Reeza
Super User

@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;
ponder
Calcite | Level 5

Thanks! That solved my problem.

For the next time i will provide more information about the problem 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 4 replies
  • 1477 views
  • 0 likes
  • 4 in conversation