BookmarkSubscribeRSS Feed
Twinklex
Fluorite | Level 6

Hi,

 

I have a requirement where I am trying to place all the column names of a dateset into an array using sas coding. Is there any possibility to that. Thanks in advance!

3 REPLIES 3
maguiremq
SAS Super FREQ

Are all your variables of the same type? If so, you can use the _all_. If not, you have to define them separately by their variable type. You can then use _numeric_ and _character_.

 

See this: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p08do6szetrxe2n136ush727sbuo.htm

 

Specifically, look at the "array elements" section.

FreelanceReinh
Jade | Level 19

Hello @Twinklex,

 

If you want to create an array of character variables, say var1, var2, ..., containing the column names (i.e. variable names) of the original dataset (e.g., SASHELP.CLASS), then try this:

proc sql noprint;
select quote(trim(name)) into: varlist separated by ' '
from dictionary.columns
where libname='SASHELP' & memname='CLASS';
quit;

data want;
array var[&sqlobs] $32 (&varlist);
/* ... code using the array ... */
run;

Or this:

proc transpose data=sashelp.class(obs=0) out=_trans;
var _all_;
run;

proc transpose data=_trans out=_temp(drop=_:) prefix=var;
var _name_;
run;

data want;
set _temp;
array var[*] var:;
/* ... code using the array ... */
run;
ballardw
Super User

Please show an example of your starting data and what you expect the result after this is applied.

It sounds very odd that you want the exact same values for every record in a data set.

 

Note that arrays do not exist after the end of data step code. Array is only a technique for manipulating something while the data step runs. After the data step the only result is variables and their values. So you really do not have much of an array elsewhere.

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