PING
0.9
Statistical data handling and processing in production environment
|
Select variables from a given dataset using the SQL-based SELECT
method.
idsn
: a dataset reference;var
: (option) list of fields/variables of idsn
upon which the extraction is performed; default: var
is empty and all variables are selected; note that (see below):varop
(see below) will operate on these variables only,all=YES
;varas
: (option) list of alias (AS
) to use for the variables in &var
; if not empty, then should be of same length as &var
; default: empty, i.e. the names of the variables are retained;varop
: (option) list of unary operations (e.g., min
, max
, ...) to run (separately) over the list of variables in &var
; if not empty, then should be of same length as &var
; note that the string _ID_
(see also variable G_PING_IDOP
) is used for the identity operation (i.e., no operation); default: empty, i.e. _ID_
is ran over all variables;where
: (option) expression used to refine the selection (WHERE
option); should be passed with %str
or %quote
; default: empty;groupby
: (option) list of variables of &idsn
used to group data (GROUP BY
option); default: empty;having
: (option) expression used to refine the selection (HAVING
option); should be passed with %str
; default: empty;orderby
: (option) list of variables of &idsn
used to group data (ORDER BY
option); default: empty;distinct
: (option) boolean flag (yes/no
) set to use the DISTINCT
option of the PROC SQL
selection procedure;all
: (option) boolean flag (yes/no
) set to keep all variables from input dataset &idsn
; in practice, a *
is added to the list of variables in &var
into the SELECT
operation; default: all=NO
, i.e. only the variables in &var
are present in the output dataset;ilib
: (option) name of the input library; by default: empty, i.e. WORK
is used.odsn
: name of the output dataset; it will contain the selection operated on the original dataset;olib
: (option) name of the output library; by default: empty, i.e. WORK
is also used;_proc_
: (option) name of a variable containing the PROC SQL
procedure; when passed, or when the debug mode is set, the operation is not actually ran, but it is returned (as a string) in this variable.Let us consider the test dataset #35:
geo | time | EQ_INC20 | RB050a |
---|---|---|---|
BE | 2009 | 10 | 10 |
BE | 2010 | 50 | 10 |
BE | 2011 | 60 | 10 |
BE | 2012 | 20 | 20 |
BE | 2013 | 10 | 20 |
BE | 2014 | 30 | 20 |
BE | 2015 | 40 | 20 |
IT | 2009 | 10 | 10 |
IT | 2010 | 50 | 10 |
IT | 2011 | 50 | 10 |
IT | 2012 | 30 | 20 |
IT | 2013 | 30 | 20 |
IT | 2014 | 20 | 20 |
IT | 2015 | 50 | 20 |
and run the following:
to create the output table TMP
:
geo | time | income | weight |
---|---|---|---|
BE | 2014 | 30 | 10 |
BE | 2011 | 60 | 10 |
BE | 2010 | 50 | 10 |
BE | 2015 | 40 | 10 |
IT | 2012 | 30 | 10 |
IT | 2011 | 50 | 10 |
IT | 2010 | 50 | 10 |
IT | 2015 | 50 | 10 |
IT | 2013 | 30 | 10 |
while in debug mode:
does not actually run the operation, but instead returns in proc
the following string that describes the implemented procedure:
Run macro %_example_ds_select
for examples.
var
is passed (as well as one varas
identifier and one operation varop
at most), and with distinct=yes, all=yes
, the macro runs the following PROC SQL
procedure:_proc_
is set, the macro is used to defines the procedure instructions: so that proc
is set to the procedure that launches the operation (see above), and while the actual operation is actually not ran. Further note that in the case the variable G_PING_DEBUG
is not defined in your environment, and _proc_
is not set, debug mode is ignored (i.e., by default the operation is ran).
where
, groupby
and having
, do not specify the corresponding keywords (i.e., WHERE
, GROUP BY
and HAVING
respectively). Ibid, for the varas
option, do no use the AS
keyword in the list of names.where
and having
should be passed using the %str
string macro when running the process, %bquote
should be preferred when running in debug mode.HAVING
and WHERE
clauses: create respectively test1
as:
a | dummy |
---|---|
and test2
as:
a | dummy |
---|---|
6 | 1 |
%ds_append, %ds_isempty, %ds_check, %sql_clause_by, %sql_clause_as, %obs_select, SELECT statement.