Hi,
I just realized that dataset END option is not possible in DS2:
<>
do until(eof);
set datasetName (locktable=share) end=eof;
<>
ERROR: Compilation error.
ERROR: Parse encountered END when expecting ';'.
ERROR: Line 0: Parse failed: datasetName (locktable=share) >>> end <<< =eof; arrayName[arKey
My intention is to load the lookup data to temporary array so that I could use it while processing the main fact table.
I managed to load the arrays using a data-> run method
data _null_;
method run();
set datasetName (locktable=share);
arrayName[arKey, arIndex] = dsField1;
.
.
.
end;
enddata;
Now, I need to access this array while processing my fact table. Unfortunately I am short of ideas to use it in the same DATA step in DS2.
Could anybody please help me?
Thanks in advance!
P.S- I have multiple look up tables to be loaded into arrays and it is too big for loading into hashes
You can load the contents of a data set into an array in the INIT method if you use the SQLSTMT package http://documentation.sas.com/?docsetId=ds2ref&docsetTarget=p154ftg7h2x9zqn11o5g7yltm3cl.htm&docsetVe... and use a FEDSQL SELECT to bring in one row at a time with the FETCH method inside a loop.
I've created a small example program which first creates two data sets and then loads one into an array inside the INIT method. Then, when the RUN method executes the contents of that array are retrieved and used to calculate the product of the number from the array and the second data set.
data one;
infile datalines;
input x;
datalines;
2
4
6
8
;
run;
data two;
infile datalines;
input y;
datalines;
10
12
14
16
;
run;
proc ds2;
data three(keep=(x,y,z)) / overwrite=yes;
dcl int n[4];
dcl int counter x y z;
retain counter;
method init();
dcl package sqlstmt stmt('select x from one');
stmt.execute();
stmt.bindResults([x]);
counter=1;
do while (stmt.fetch()=0);
n[counter]=x;
counter=counter+1;
end;
end;
method run();
set two;
if _n_=1 then counter=1;
x=n[_n_];
z=x*y;
counter=counter+1;
end;
enddata;
run;
quit;
You should be able to use this technique of loading the array in the INIT method in your code - please let me know if there's anything in there you don't follow.
Could you put the readin of data for the lookup table in a method init? Then the run method could access the lookup values,right?
I did try to load the lookup tables in init() :
method init();
if 0 then set dsName (locktable=share);
do rLoop=1 to &dsObs.;
put rLoop=;
set dsName (locktable=share);
arrayName[arKey + 1,arIndex] = dsField1;
.
.
.
end;
end;
But, now I get following errors:
rloop=1
ERROR: Integer divide by zero
ERROR: Integer divide by zero
ERROR: General error
ERROR: Access violation
ERROR: Access violation
Does anybody have any clue on this?
Can you tell us why you want to use END - it's not clear to me why it's necessary in this case. If you give us some more of the code we might be able to offer an alternative way of doing what you want.
You can load the contents of a data set into an array in the INIT method if you use the SQLSTMT package http://documentation.sas.com/?docsetId=ds2ref&docsetTarget=p154ftg7h2x9zqn11o5g7yltm3cl.htm&docsetVe... and use a FEDSQL SELECT to bring in one row at a time with the FETCH method inside a loop.
I've created a small example program which first creates two data sets and then loads one into an array inside the INIT method. Then, when the RUN method executes the contents of that array are retrieved and used to calculate the product of the number from the array and the second data set.
data one;
infile datalines;
input x;
datalines;
2
4
6
8
;
run;
data two;
infile datalines;
input y;
datalines;
10
12
14
16
;
run;
proc ds2;
data three(keep=(x,y,z)) / overwrite=yes;
dcl int n[4];
dcl int counter x y z;
retain counter;
method init();
dcl package sqlstmt stmt('select x from one');
stmt.execute();
stmt.bindResults([x]);
counter=1;
do while (stmt.fetch()=0);
n[counter]=x;
counter=counter+1;
end;
end;
method run();
set two;
if _n_=1 then counter=1;
x=n[_n_];
z=x*y;
counter=counter+1;
end;
enddata;
run;
quit;
You should be able to use this technique of loading the array in the INIT method in your code - please let me know if there's anything in there you don't follow.
Hi Chris,
This helped, Thanks a lot for being so kind to illustrate the functionalities of SQLSTMT package!
Thanks,
Dilip
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.