Published on :
Export CREATION_INTERNE

Export CSV to Web Stream (_webout)

This code is also available in: Deutsch Español Français
Awaiting validation
This script first creates an internal 'test' dataset containing simulated financial information (name, amount, year) via the CARDS statement. It then uses a Data _NULL_ step to write this data, along with a header row, to the '_webout' fileref with a comma delimiter. This technique is typically used in SAS© Job Execution services or Stored Processes to dynamically return a CSV file to the client browser.
Data Analysis

Type : CREATION_INTERNE


The data is entirely defined in the source code via a CARDS/DATALINES section.

1 Code Block
DATA STEP Data
Explanation :
Creation of the temporary 'test' table defining the data structure (length, type) and loading raw data included in the script.
Copied!
1DATA test ;
2 LENGTH name spent $ 4 year 8 ;
3 INPUT name & spent & year ;
4 CARDS ;
5Mr A $40 2011
6Mr B $10 2011
7Mr C $40 2011
8Mr A $70 2012
9Mr B $20 2012
10Mr B $50 2013
11Mr C $30 2013
12;;
13RUN ;
2 Code Block
DATA STEP
Explanation :
Reading the 'test' table and writing line by line to the '_webout' destination (HTTP stream). Conditional addition of the CSV header on the first iteration (_n_=1).
Copied!
1DATA _null_ ;
2 file _webout delimiter=',' ;
3 SET test END=_end ;
4 IF _n_=1 THEN put 'Name,Spent,Year' ;
5 put name spent year ;
6RUN ;
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.