diff --git a/README.md b/README.md index 9954177..a80104b 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,11 @@ The package allows to write SQL queries in the data step, e.g. set %SQL(select name, age from sashelp.class order by age); run; ``` -SHA256 digest for the latest version of `SQLinDS`: F*6CC51325BDCE164B2E811896DD1C3A6D44242F50CC313D0721350CA49975F628 +SHA256 digest for the latest version of `SQLinDS`: F*A3DC9400DEF1403DC9E191611790244A8B0FB23303D3A98D29777E46A1D4E8B4 [**Documentation for SQLinDS**](./sqlinds.md "Documentation for SQLinDS") +Recording form SAS Innovate 2026 Users Day: ["SQLinDS and evExpress SAS packages - a tribute to SAS rock-stars!"](https://www.youtube.com/watch?v=ONSmt_l2TtU&t=6433s "SAS Innovate 2026 Users Day") (April 27th 2026, ~30 minutes) + To work with a package use the [**SAS Packages Framework**](https://github.com/yabwon/SAS_PACKAGES/blob/main/README.md "SPFinit"). diff --git a/hist/2.4.0/sqlinds.md b/hist/2.4.0/sqlinds.md new file mode 100644 index 0000000..6710c89 --- /dev/null +++ b/hist/2.4.0/sqlinds.md @@ -0,0 +1,273 @@ +# Documentation for the `SQLinDS` package. + +---------------------------------------------------------------- + + *SQL queries in Data Step* + +---------------------------------------------------------------- + +### Version information: + +- Package: SQLinDS +- Version: 2.4.0 +- Generated: 2026-05-11T14:15:07 +- Author(s): Mike Rhoads (RhoadsM1@Westat.com), contributor Bartosz Jablonski +- Maintainer(s): Bartosz Jablonski (yabwon@gmail.com) +- License: MIT +- File SHA256: `F*A3DC9400DEF1403DC9E191611790244A8B0FB23303D3A98D29777E46A1D4E8B4` for this version +- Content SHA256: `C*4A49F365C4EF8C5523393FDC1E11C344B023F449B3F1759BA27CFC6C1293A499` for this version + +--- + +# The `SQLinDS` package, version: `2.4.0`; + +--- + + +The **SQLinDS** package is an implementation of +the *macro-function-sandwich* concept introduced in the +*"Use the Full Power of SAS in Your Function-Style Macros"*, +the article by *Mike Rhoads (Westat, Rockville)*. + +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) + +Copy of the article can also be found in *additional content* directory. + +Package provides ability to *execute* SQL queries inside a data step, e.g. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas + data class; + set %SQL(select name, age from sashelp.class); + run; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +See the help for the `%SQL()` macro to find more examples. + +### Content ################################################################### + +SQLinDS package contains the following components: + +1. `%SQL()` macro - the main package macro available for the User +2. `dsSQL()` function (internal) +3. `%dsSQL_inner()` macro (internal) +4. Library `DSSQL` (created as a subdirectory of the `WORK` library) +5. Optional KMF-abbreviations `sqlinds` + +--- + + +--- + + +--- + +Required SAS Components: + - Base SAS Software + +--- + + +--- + +Package contains additional content, run: `%loadPackageAddCnt(SQLinDS)` to load it +or look for the `sqlinds_AdditionalContent` directory in the `packages` fileref +localization (only if additional content was deployed during the installation process). + +--------------------------------------------------------------------- + +*SAS package generated by SAS Package Framework, version `20260411`,* +*under `WIN`(`X64_10PRO`) operating system,* +*using SAS release: `9.04.01M9P06052025`.* + +--------------------------------------------------------------------- + +# The `SQLinDS` package content +The `SQLinDS` package consists of the following content: + +1. [`dssql` libname ](#dssql-libname-1 ) +2. [`%dssql_inner()` macro ](#dssqlinner-macro-2 ) +3. [`%sql()` macro ](#sql-macro-3 ) +4. [`dssql()` function ](#dssql-function-4 ) +5. [`sqlinds` kmfsnip ](#sqlinds-kmfsnip-5 ) + + +6. [License note](#license) + +--- + +## `dssql` libname ###### + +The `dsSQL` library stores temporary views +generated during the `%SQL()` macro execution. + +If possible a sub-directory of the `WORK` location is created, like: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))/dsSQLtmp"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +if not possible, then redirects to the `WORK` location, like: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +--- + + +--- + +## `%dssql_inner()` macro ###### + +The `%dsSQL_Inner()` macro is an **internal** +macro called by `dsSQL()` function. + +The macro generates a uniquely named SQL view on the fly +which is then stored in the `dsSQL` library. + +The `%dsSQL_Inner()` is *not* designed to be +called on its own. + +Recommended for *SAS 9.3* and higher. + +--- + + +--- + +## `%sql()` macro ###### + +The `%SQL()` macro is the **main** +macro in the package. The macro allows +to use SQL queries in the data step. + +Recommended for *SAS 9.3* and higher. + +Implementation is based on the article: +*"Use the Full Power of SAS in Your Function-Style Macros"* +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) + +Copy of the article can also be found in *additional content* directory. + +### SYNTAX: ################################################################### +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +%sql() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The query code is limited to approximately *32000* bytes. + +### EXAMPLES: ################################################################# + +**EXAMPLE 1**: A simple SQL query. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +data class_subset; + set %SQL(select name, sex, height from sashelp.class where age > 12); +run; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**EXAMPLE 2**: A query with dataset options. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +data renamed; + set %SQL(select name, age from sashelp.class + where sex = "F")(rename = (age=age2) + ); +run; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**EXAMPLE 3**: Proc SQL dictionaries in the data step. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +data dictionary; + set %SQL(select dict.* from dictionary.macros as dict); +run; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**EXAMPLE 4**: Use Proc SQL to populate hash table. + Call to `%SQL()` has to be in double-quotes. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +data _null_; + if 0 then set %SQL(SELECT name, age FROM sashelp.class); + + declare hash H (dataset: "%SQL(SELECT name, age FROM sashelp.class)") ; + H.defineKey("age"); + H.defineKey("name"); + H.defineDone(); + + H.output(dataset:"output"); + stop; +run; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +--- + + +--- + +## `dssql()` function ###### + +The `dsSQL()` function is an **internal** +function called by the `%SQL()` macro. + +The function pass a query code from the `%SQL()` +macro to the `%dsSQL_Inner()` internal macro. + +The `dsSQL()` is *not* designed to be +called on its own. + +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. + +--- + + +--- + +## `sqlinds` kmfsnip ###### +This is a help note for `sqlinds` KMF-abbreviation. + +The snippet presents a template +for use of the `%SQL()` macro. + +To read help info about the macro +run he following: +`%helpPackage(SQLinDS,'%sql()')` + + +--- + + +--- + +# License ###### + +Copyright (c) since 2012 onward, Mike Rhoads + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +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 +SOFTWARE. + +--- + diff --git a/hist/2.4.0/sqlinds.zip b/hist/2.4.0/sqlinds.zip new file mode 100644 index 0000000..2667cbe Binary files /dev/null and b/hist/2.4.0/sqlinds.zip differ diff --git a/sqlinds.md b/sqlinds.md index fbe0221..6710c89 100644 --- a/sqlinds.md +++ b/sqlinds.md @@ -9,17 +9,17 @@ ### Version information: - Package: SQLinDS -- Version: 2.3.3 -- Generated: 2026-02-17T08:25:24 +- Version: 2.4.0 +- Generated: 2026-05-11T14:15:07 - Author(s): Mike Rhoads (RhoadsM1@Westat.com), contributor Bartosz Jablonski - Maintainer(s): Bartosz Jablonski (yabwon@gmail.com) - License: MIT -- File SHA256: `F*6CC51325BDCE164B2E811896DD1C3A6D44242F50CC313D0721350CA49975F628` for this version -- Content SHA256: `C*776741E40EB6DCD907640ACA674F092BFAF0F7DE031519B6B453D37F6D6959D9` for this version +- File SHA256: `F*A3DC9400DEF1403DC9E191611790244A8B0FB23303D3A98D29777E46A1D4E8B4` for this version +- Content SHA256: `C*4A49F365C4EF8C5523393FDC1E11C344B023F449B3F1759BA27CFC6C1293A499` for this version --- -# The `SQLinDS` package, version: `2.3.3`; +# The `SQLinDS` package, version: `2.4.0`; --- @@ -75,9 +75,9 @@ localization (only if additional content was deployed during the installation pr --------------------------------------------------------------------- -*SAS package generated by SAS Package Framework, version `20260216`,* +*SAS package generated by SAS Package Framework, version `20260411`,* *under `WIN`(`X64_10PRO`) operating system,* -*using SAS release: `9.04.01M9P06042025`.* +*using SAS release: `9.04.01M9P06052025`.* --------------------------------------------------------------------- @@ -155,18 +155,18 @@ Copy of the article can also be found in *additional content* directory. %sql() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The THE query code is limited to approximately *32000* bytes. +The query code is limited to approximately *32000* bytes. ### EXAMPLES: ################################################################# -**EXAMPLE 1**: simple SQL query +**EXAMPLE 1**: A simple SQL query. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas data class_subset; set %SQL(select name, sex, height from sashelp.class where age > 12); run; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -**EXAMPLE 2**: query with dataset options +**EXAMPLE 2**: A query with dataset options. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas data renamed; set %SQL(select name, age from sashelp.class @@ -175,12 +175,28 @@ data renamed; run; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -**EXAMPLE 3**: Proc SQL dictionaries in the data step +**EXAMPLE 3**: Proc SQL dictionaries in the data step. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas data dictionary; set %SQL(select dict.* from dictionary.macros as dict); run; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**EXAMPLE 4**: Use Proc SQL to populate hash table. + Call to `%SQL()` has to be in double-quotes. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas +data _null_; + if 0 then set %SQL(SELECT name, age FROM sashelp.class); + + declare hash H (dataset: "%SQL(SELECT name, age FROM sashelp.class)") ; + H.defineKey("age"); + H.defineKey("name"); + H.defineDone(); + + H.output(dataset:"output"); + stop; +run; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- diff --git a/sqlinds.zip b/sqlinds.zip index 21f121a..2667cbe 100644 Binary files a/sqlinds.zip and b/sqlinds.zip differ