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!
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.
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;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.