SQLinDS, version 2.2

SQLinDS, version 2.2
- documentation updated, macroarray.md created
This commit is contained in:
yabwon
2020-09-15 13:02:37 +02:00
parent 8c584c8030
commit d53f622776
2 changed files with 63 additions and 23 deletions

View File

@@ -1,5 +1,14 @@
- [The SQLinDS package [ver. 2.2]](#sqlinds-package)
- [Content description](#content-description)
* [library `dsSQL`](#library-dssql)
* [`%dsSQL_inner()` macro](#dssql-inner-macro)
* [`%SQL()` macro](#dssql-inner-macro)
* [`dsSQL()` function](#dssql-function)
* [License](#license)
---
# The SQLinDS package [ver. 2.2] ############################################### # The SQLinDS package [ver. 2.2] <a name="sqlinds-package"></a> ###############################################
The **SQLinDS** package is an implementation of The **SQLinDS** package is an implementation of
the *macro-function-sandwich* concept introduced in the the *macro-function-sandwich* concept introduced in the
@@ -9,8 +18,8 @@ the article by *Mike Rhoads (Westat, Rockville)*.
Copy of the article is available at: Copy of the article is available at:
[https://support.sas.com/resources/papers/proceedings12/004-2012.pdf](https://support.sas.com/resources/papers/proceedings12/004-2012.pdf) [https://support.sas.com/resources/papers/proceedings12/004-2012.pdf](https://support.sas.com/resources/papers/proceedings12/004-2012.pdf)
Package provides ability to *execute* SQL queries inside a datastep, e.g. Package provides ability to *execute* SQL queries inside a data step, e.g.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
data class; data class;
set %SQL(select * from sashelp.class); set %SQL(select * from sashelp.class);
run; run;
@@ -26,45 +35,59 @@ SQLinDS package contains the following components:
3. `%dsSQL_inner()` macro (internal) 3. `%dsSQL_inner()` macro (internal)
4. Library `DSSQL` (created as a subdirectory of the `WORK` library) 4. Library `DSSQL` (created as a subdirectory of the `WORK` library)
---
Package contains:
1. libname dssql
2. macro dssql_inner
3. macro sql
4. function dssql
Required SAS Components: Required SAS Components:
Base SAS Software *Base SAS Software*
*SAS package generated by generatePackage, version 20200911* *SAS package generated by generatePackage, version 20200911*
The SHA256 hash digest for package SQLinDS: The SHA256 hash digest for package SQLinDS:
`DD5E319EB5AA29C7054EC428072F987E77C29D36874DED1AE5C62E4B300845EB` `B280D0B72DB77001ADAAE9C1612B67AD30C2C672371B27F1ACB12016C7A1363D`
---
# Content description ############################################################################################
### Content description ####################################################### ## >>> library `dsSQL`: <<< <a name="library-dssql"></a> ########################
## >>> library `dsSQL`: <<< ################################### The `dsSQL` library stores temporary views
The dsSQL library stores temporary views
generated during the `%SQL()` macro execution. generated during the `%SQL()` macro execution.
If possible a subdirectory of the `WORK` location is created, like: If possible a subdirectory of the `WORK` location is created, like:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))/dsSQLtmp"; LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))/dsSQLtmp";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if not possible, then redirects to the `WORK` location, like: if not possible, then redirects to the `WORK` location, like:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))"; LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%dsSQL_Inner()` macro: <<< #############################################
## >>> `%dsSQL_Inner()` macro: <<< <a name="dssql-inner-macro"></a> #############
**Internal** macro called by `dsSQL()` function. **Internal** macro called by `dsSQL()` function.
The macro generates a uniqualy named sql view on the fly The macro generates a uniquely named SQL view on the fly
which is then stored in the `DSSQL` library. which is then stored in the `dsSQL` library.
Recommended for *SAS 9.3* and higher. Recommended for *SAS 9.3* and higher.
---
## >>> `%SQL()` macro: <<< #####################################################
The *main* macro which allows to use
## >>> `%SQL()` macro: <<< <a name="dssql-macro"></a> ###########################
The **main** macro which allows to use
SQL queries in the data step. SQL queries in the data step.
Recommended for *SAS 9.3* and higher. Recommended for *SAS 9.3* and higher.
@@ -74,37 +97,39 @@ by *Mike Rhoads* (Westat, Rockville), available at:
[https://support.sas.com/resources/papers/proceedings12/004-2012.pdf](https://support.sas.com/resources/papers/proceedings12/004-2012.pdf) [https://support.sas.com/resources/papers/proceedings12/004-2012.pdf](https://support.sas.com/resources/papers/proceedings12/004-2012.pdf)
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%sql(<nonempty sql querry code>) %sql(<nonempty sql querry code>)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The sql querry code is limited to *32000* bytes. The sql query code is limited to *32000* bytes.
### EXAMPLES: ################################################################# ### EXAMPLES: #################################################################
**EXAMPLE 1**: simple SQL query **EXAMPLE 1**: simple SQL query
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
data class_subset; data class_subset;
set %SQL(select name, sex, height from sashelp.class where age > 12); set %SQL(select name, sex, height from sashelp.class where age > 12);
run; run;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**EXAMPLE 2**: query with dataset options **EXAMPLE 2**: query with dataset options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
data renamed; data renamed;
set %SQL(select * from sashelp.class where sex = "F")(rename = (age=age2)); set %SQL(select * from sashelp.class where sex = "F")(rename = (age=age2));
run; run;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**EXAMPLE 3**: dictionaries in the data step **EXAMPLE 3**: dictionaries in the data step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
data dictionary; data dictionary;
set %SQL(select * from dictionary.macros); set %SQL(select * from dictionary.macros);
run; run;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `dsSQL()` function: <<< #################################################
## >>> `dsSQL()` function: <<< <a name="dssql-function"></a> ####################
**Internal** function called by the `%SQL()` macro. **Internal** function called by the `%SQL()` macro.
The function pass a query code from the `%SQL()` The function pass a query code from the `%SQL()`
@@ -112,8 +137,21 @@ macro to the `%dsSQL_Inner()` internal macro.
Recommended for *SAS 9.3* and higher. Recommended for *SAS 9.3* and higher.
### SYNTAX: ###################################################################
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
dsSQL(unique_index_2, query)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Arguments description**:
1. `unique_index_2` - *Numeric*, internal variable, a unique index for views.
2. `query` - *Character*, internal variable, contains query text.
---
## License #################################################################### ## License ####################################################################
Copyright (c) 2012 Mike Rhoads Copyright (c) 2012 Mike Rhoads
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -132,4 +170,6 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
---

Binary file not shown.