DATA Step, Macro, Functions and more

Access specifics columns in a table with large number of columns

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Access specifics columns in a table with large number of columns

Hi,

I want to access specific columns in a SAS table (more than 1000 columns)  within a DO loop : for example column number 2 until column before the last one in order to do some specific treatements for each column. How can we do that ?

Thanks


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 7,771

Re: Access specifics columns in a table with large number of columns

You might give us some clue about the structure of the dataset, regarding order of variables, and which need to be treated.

You still can use two arrays for _numeric_ and _character_, and iterate separately through both.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 7,771

Re: Access specifics columns in a table with large number of columns

As long as all the variables you want to treat are of the same type (character or numeric), you can define an array over them and iterate through that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 2

Re: Access specifics columns in a table with large number of columns

Posted in reply to KurtBremser

Thnks for your reply but unfortunately this is not the case. There is as many numerics as characters.

Solution
‎09-25-2015 06:23 AM
Super User
Posts: 7,771

Re: Access specifics columns in a table with large number of columns

You might give us some clue about the structure of the dataset, regarding order of variables, and which need to be treated.

You still can use two arrays for _numeric_ and _character_, and iterate separately through both.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,039

Re: Access specifics columns in a table with large number of columns

You cannot easily do that, and in general it would make no sense.

You can define arrays.  You can use Variable Lists

array all_num _numeric_ ;
array all_str _character_;
array some_num firstvar-numeric-lastvar ;
array some_str firstchar-character-lastchar ;

What is the actual PROBLEM that you are trying to solve?  Perhaps there is another way to do it that does not requiring treating your dataset as if it was a spreadsheet.

 

 

 

 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 244 views
  • 1 like
  • 3 in conversation