BookmarkSubscribeRSS Feed
tom12122
Obsidian | Level 7

Is there a possibility to easily insert data set into 2-dimensional  array?

The data set can have variable column count and names.

Is there a way to reference columns by position instead by column name in data step?

2 REPLIES 2
data_null__
Jade | Level 19

I would consider loading the data set into a hash object.  Perhaps with an iterator so you can treat it like and array using the iterator methods FIRST NEXT and the rest.

Ksharp
Super User

"Is there a possibility to easily insert data set into 2-dimensional  array?"

Yes. EASY. but you only can hold one type variables, that means numeric or character .

data class;

set sashelp.class;

keep _numeric_;

run;

%let dsid=%sysfunc(open(class,i));

%let nobs=%sysfunc(attrn(&dsid,nobs));

%let nvar=%sysfunc(attrn(&dsid,nvar));

%let dsid=%sysfunc(close(&dsid));

data _null_;

set class end=last;

array a{&nvar] _numeric_;

array _a{&nobs,&nvar} _temporary_;

do j=1 to dim(a);

    _a{_n_,j}=a{j};

  end;

if last then do;

do m=1 to &nobs;

  do n=1 to &nvar;

   put _a{m,n}= ;

  end;

end;

end;

run;

"The data set can have variable column count and names.

Is there a way to reference columns by position instead by column name in data step?"

Yes. There is a function to get it. Check it at SAS Documentation.

Ksharp

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1296 views
  • 0 likes
  • 3 in conversation