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?
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.
"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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.