Published on :

DataGridProvider

This code is also available in: Deutsch Español Français
Awaiting validation
This script is designed to be executed as a Stored Process or a SAS© Job. It takes macro parameters (dset, start, limit) as input to define the source table and the pagination window. It calculates the total number of observations, extracts the requested subset into a temporary table, then manually generates a JSON structure containing the total number of records and the data array for the requested page, all sent to the web output stream (_webout).
Data Analysis

Type : MIXTE


By default, the script uses 'sashelp.class' via the %defaults macro. The source table can be dynamically modified via the 'dset' macro variable. A 'dtemp' library pointing to 'D:\Temp' is defined but not explicitly used in the main transformation logic.

1 Code Block
LIBNAME
Explanation :
Definition of a temporary library (Windows path, to be adapted for Viya/Linux).
Copied!
1LIBNAME dtemp 'D:\Temp';
2 Code Block
MACRO
Explanation :
Initialization of default parameters (source table, start, limit) if not provided by the calling environment.
Copied!
1%macro defaults ;
2 %IF %symexist(dset)=0 %THEN %DO;
3 %global dset;
4 %let dset=sashelp.class;
5 %END;
6 %IF ^%symexist(start) %THEN %DO; %global start; %let start=0; %END;
7 %IF ^%symexist(limit) %THEN %DO; %global limit; %let limit=160; %END;
8%mend defaults;
9%defaults
3 Code Block
DATA STEP
Explanation :
Opening the source table to retrieve the total number of observations ('nobs' metadata) and storing it in a macro variable.
Copied!
1DATA _null_ ;
2 dsid=open("&dset");
3 nobs=attrn(dsid,'nobs');
4 call symput('nobs',strip(put(nobs,8.)));
5RUN;
4 Code Block
MACRO
Explanation :
Calculation of pagination bounds (first and last record to extract).
Copied!
1%let first=%eval(&start+1);
2%let last=%eval(&start+&limit);
3%put first=&first last=&last nobs=&nobs;
4 
5 Code Block
DATA STEP Data
Explanation :
Creation of the 'subset' table containing only the data for the requested page.
Copied!
1 
2DATA subset;
3SET &dset (firstobs=&first obs=&last);
4RUN;
5 
6 Code Block
DATA STEP
Explanation :
DATA _NULL_ step that iterates through the 'subset' table and manually writes a formatted JSON structure (totalCount, rows) to the '_webout' output filestream. The code dynamically inspects variable types (numeric or character) to correctly format JSON values.
Copied!
1DATA _null_ ;
2 LENGTH type $ 1 char $ 128 num 8;
3 file _webout;
4 dsid=open("subset");
5 /* ... logique de génération JSON ... */
6 dsid=close(dsid);
7RUN;
7 Code Block
MACRO
Explanation :
Calling standard Stored Process macros to finalize execution and manage output.
Copied!
1%let _result=streamfragment ;
2%STPBEGIN;
3/* ... */
4%STPEND;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.