mirror of
https://github.com/yabwon/SAS_PACKAGES.git
synced 2026-01-08 07:20:06 +00:00
version 20200511
Help info added
This commit is contained in:
@@ -3,12 +3,12 @@
|
|||||||
/* >>> dsSQL library: <<<
|
/* >>> dsSQL library: <<<
|
||||||
*
|
*
|
||||||
* The dsSQL library stores temporary views
|
* The dsSQL library stores temporary views
|
||||||
* generated during %SQL() macro's execution.
|
* generated during the %SQL() macro execution.
|
||||||
* If possible, created as a subdirectory of WORK:
|
* If possible a subdirectory of WORK is created as:
|
||||||
|
|
||||||
LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))/dsSQLtmp";
|
LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))/dsSQLtmp";
|
||||||
|
|
||||||
* if not then redirected to WORK
|
* if not possible then redirects to WORK as:
|
||||||
|
|
||||||
LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))";
|
LIBNAME dsSQL BASE "%sysfunc(pathname(WORK))";
|
||||||
|
|
||||||
@@ -25,6 +25,5 @@ data _null_;
|
|||||||
rc1 = LIBNAME("dsSQL", "%sysfunc(pathname(work))", "BASE");
|
rc1 = LIBNAME("dsSQL", "%sysfunc(pathname(work))", "BASE");
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
/* list details about the library in the log */
|
||||||
libname dsSQL LIST;
|
libname dsSQL LIST;
|
||||||
;
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
/*** HELP START ***/
|
/*** HELP START ***/
|
||||||
|
|
||||||
/* >>> %dsSQL_Inner() macro: <<<
|
/* >>> %dsSQL_Inner() macro: <<<
|
||||||
*
|
*
|
||||||
* Internal macro called by dsSQL() function.
|
* Internal macro called by dsSQL() function.
|
||||||
|
* The macro generates a uniqualy named sql view on the fly
|
||||||
|
* which is stored in DSSQL library.
|
||||||
*
|
*
|
||||||
* Recommended for SAS 9.3 and higher.
|
* Recommended for SAS 9.3 and higher.
|
||||||
* Based on paper:
|
* Based on paper:
|
||||||
|
|||||||
@@ -10,13 +10,19 @@
|
|||||||
* by Mike Rhoads, Westat, Rockville, MD
|
* by Mike Rhoads, Westat, Rockville, MD
|
||||||
* https://support.sas.com/resources/papers/proceedings12/004-2012.pdf
|
* https://support.sas.com/resources/papers/proceedings12/004-2012.pdf
|
||||||
*
|
*
|
||||||
|
* SYNTAX:
|
||||||
|
|
||||||
|
%sql(<nonempty sql querry code>)
|
||||||
|
|
||||||
|
* The sql querry code is limited to 32000 bytes.
|
||||||
|
*
|
||||||
* EXAMPLE 1: simple sql query
|
* EXAMPLE 1: simple sql query
|
||||||
|
|
||||||
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: with dataset options
|
* EXAMPLE 2: query with dataset options
|
||||||
|
|
||||||
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));
|
||||||
@@ -33,15 +39,15 @@
|
|||||||
/*** HELP END ***/
|
/*** HELP END ***/
|
||||||
|
|
||||||
|
|
||||||
/* outer macro */
|
/* Main User macro */
|
||||||
%MACRO SQL() / PARMBUFF SECURE;
|
%MACRO SQL() / PARMBUFF SECURE;
|
||||||
%let SYSPBUFF = %superq(SYSPBUFF); /* macroquoting */
|
%let SYSPBUFF = %superq(SYSPBUFF); /* macroquoting */
|
||||||
%let SYSPBUFF = %substr(&SYSPBUFF, 2, %LENGTH(&SYSPBUFF) - 2); /* remove brackets */
|
%let SYSPBUFF = %substr(&SYSPBUFF, 2, %LENGTH(&SYSPBUFF) - 2); /* remove brackets */
|
||||||
%let SYSPBUFF = %superq(SYSPBUFF); /* macroquoting */
|
%let SYSPBUFF = %superq(SYSPBUFF); /* macroquoting */
|
||||||
%let SYSPBUFF = %sysfunc(quote(&SYSPBUFF)); /* quotes */
|
%let SYSPBUFF = %sysfunc(quote(&SYSPBUFF)); /* quotes */
|
||||||
%put NOTE-***the query***; /* print out the query in the log */
|
%put NOTE:*** the query ***; /* print out the query in the log */
|
||||||
%put NOTE-&SYSPBUFF.;
|
%put NOTE-&SYSPBUFF.;
|
||||||
%put NOTE-****************;
|
%put NOTE-*****************;
|
||||||
|
|
||||||
%local UNIQUE_INDEX; /* internal variable, a unique index for views */
|
%local UNIQUE_INDEX; /* internal variable, a unique index for views */
|
||||||
%let UNIQUE_INDEX = &SYSINDEX;
|
%let UNIQUE_INDEX = &SYSINDEX;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
/* >>> dsSQL() function: <<<
|
/* >>> dsSQL() function: <<<
|
||||||
*
|
*
|
||||||
* Internal function called by %SQL() macro.
|
* Internal function called by %SQL() macro.
|
||||||
|
* The function pass query code from the %SQL()
|
||||||
|
* macro to the %dsSQL_Inner() innternal macreo.
|
||||||
*
|
*
|
||||||
* Recommended for SAS 9.3 and higher.
|
* Recommended for SAS 9.3 and higher.
|
||||||
* Based on paper:
|
* Based on paper:
|
||||||
|
|||||||
@@ -23,14 +23,23 @@ the macro-function-sandwich concept introduced in:
|
|||||||
"Use the Full Power of SAS in Your Function-Style Macros"
|
"Use the Full Power of SAS in Your Function-Style Macros"
|
||||||
the article by Mike Rhoads, Westat, Rockville, MD
|
the article by Mike Rhoads, Westat, Rockville, MD
|
||||||
|
|
||||||
Copy of the article can be found 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
|
||||||
|
|
||||||
SQLinDS package provides following components:
|
Package provides ability to "execute" SQL queries inside a datastep, e.g.
|
||||||
1) %dsSQL_inner() macro
|
|
||||||
2) dsSQL() function
|
|
||||||
3) %SQL() macro
|
|
||||||
|
|
||||||
Library DSSQL is created in a subdirectory of the WORK library.
|
data class;
|
||||||
|
set %SQL(select * from sashelp.class);
|
||||||
|
run;
|
||||||
|
|
||||||
|
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 in a subdirectory of the WORK library)
|
||||||
|
|
||||||
|
See help for the %SQL() macro to find more examples.
|
||||||
|
|
||||||
DESCRIPTION END:
|
DESCRIPTION END:
|
||||||
|
|||||||
BIN
sqlinds.zip
BIN
sqlinds.zip
Binary file not shown.
Reference in New Issue
Block a user