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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.