mirror of
https://github.com/sasjs/core.git
synced 2026-01-07 01:20:05 +00:00
feat: updating mp_lib2cards to enable a single file to be created with all the tables for a particular library
This commit is contained in:
92
all.sas
92
all.sas
@@ -2441,25 +2441,27 @@ run;
|
|||||||
@brief Create a CARDS file from a SAS dataset.
|
@brief Create a CARDS file from a SAS dataset.
|
||||||
@details Uses dataset attributes to convert all data into datalines.
|
@details Uses dataset attributes to convert all data into datalines.
|
||||||
Running the generated file will rebuild the original dataset.
|
Running the generated file will rebuild the original dataset.
|
||||||
usage:
|
Usage:
|
||||||
|
|
||||||
%mp_ds2cards(base_ds=sashelp.class
|
%mp_ds2cards(base_ds=sashelp.class
|
||||||
, cards_file= "C:\temp\class.sas"
|
, cards_file= "C:\temp\class.sas"
|
||||||
, maxobs=5)
|
, maxobs=5)
|
||||||
|
|
||||||
stuff to add
|
TODO:
|
||||||
- labelling the dataset
|
- labelling the dataset
|
||||||
- explicity setting a unix LF
|
- explicity setting a unix LF
|
||||||
- constraints / indexes etc
|
- constraints / indexes etc
|
||||||
|
|
||||||
@param base_ds= Should be two level - eg work.blah. This is the table that
|
@param [in] base_ds= Should be two level - eg work.blah. This is the table that
|
||||||
is converted to a cards file.
|
is converted to a cards file.
|
||||||
@param tgt_ds= Table that the generated cards file would create. Optional -
|
@param [in] tgt_ds= Table that the generated cards file would create. Optional -
|
||||||
if omitted, will be same as BASE_DS.
|
if omitted, will be same as BASE_DS.
|
||||||
@param cards_file= Location in which to write the (.sas) cards file
|
@param [out] cards_file= Location in which to write the (.sas) cards file
|
||||||
@param maxobs= to limit output to the first <code>maxobs</code> observations
|
@param [in] maxobs= to limit output to the first <code>maxobs</code> observations
|
||||||
@param showlog= whether to show generated cards file in the SAS log (YES/NO)
|
@param [in] showlog= whether to show generated cards file in the SAS log (YES/NO)
|
||||||
@param outencoding= provide encoding value for file statement (eg utf-8)
|
@param [in] outencoding= provide encoding value for file statement (eg utf-8)
|
||||||
|
@param [in] append= If NO then will rebuild the cards file if it already exists,
|
||||||
|
otherwise will append to it. Used by the mp_lib2cards.sas macro.
|
||||||
|
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@@ -2472,6 +2474,7 @@ run;
|
|||||||
,random_sample=NO
|
,random_sample=NO
|
||||||
,showlog=YES
|
,showlog=YES
|
||||||
,outencoding=
|
,outencoding=
|
||||||
|
,append=NO
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%local i setds nvars;
|
%local i setds nvars;
|
||||||
|
|
||||||
@@ -2484,6 +2487,8 @@ run;
|
|||||||
%if (&tgt_ds = ) %then %let tgt_ds=&base_ds;
|
%if (&tgt_ds = ) %then %let tgt_ds=&base_ds;
|
||||||
%if %index(&tgt_ds,.)=0 %then %let tgt_ds=WORK.%scan(&base_ds,2,.);
|
%if %index(&tgt_ds,.)=0 %then %let tgt_ds=WORK.%scan(&base_ds,2,.);
|
||||||
%if ("&outencoding" ne "") %then %let outencoding=encoding="&outencoding";
|
%if ("&outencoding" ne "") %then %let outencoding=encoding="&outencoding";
|
||||||
|
%if ("&append" = "") %then %let append=;
|
||||||
|
%else %let append=mod;
|
||||||
|
|
||||||
/* get varcount */
|
/* get varcount */
|
||||||
%let nvars=0;
|
%let nvars=0;
|
||||||
@@ -2610,7 +2615,7 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &cards_file. &outencoding lrecl=32767 termstr=nl;
|
file &cards_file. &outencoding lrecl=32767 termstr=nl &append;
|
||||||
length __attrib $32767;
|
length __attrib $32767;
|
||||||
if _n_=1 then do;
|
if _n_=1 then do;
|
||||||
put '/*******************************************************************';
|
put '/*******************************************************************';
|
||||||
@@ -4013,21 +4018,26 @@ create table &outds (rename=(
|
|||||||
%mend;/**
|
%mend;/**
|
||||||
@file
|
@file
|
||||||
@brief Convert all library members to CARDS files
|
@brief Convert all library members to CARDS files
|
||||||
@details Gets list of members then calls the <code>%mp_ds2cards()</code>
|
@details Gets list of members then calls the <code>%mp_ds2cards()</code> macro.
|
||||||
macro
|
Usage:
|
||||||
usage:
|
|
||||||
|
|
||||||
%mp_lib2cards(lib=sashelp
|
%mp_lib2cards(lib=sashelp
|
||||||
, outloc= C:\temp )
|
, outloc= C:\temp )
|
||||||
|
|
||||||
|
The output will be one cards file in the `outloc` directory per dataset in the
|
||||||
|
input `lib` library. If the `outloc` directory does not exist, it is created.
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mf_mkdir.sas
|
@li mf_mkdir.sas
|
||||||
|
@li mf_trimstr.sas
|
||||||
@li mp_ds2cards.sas
|
@li mp_ds2cards.sas
|
||||||
|
|
||||||
@param lib= Library in which to convert all datasets
|
@param [in] lib= Library in which to convert all datasets
|
||||||
@param outloc= Location in which to store output. Defaults to WORK library.
|
@param [out] outloc= Location in which to store output. Defaults to WORK
|
||||||
Do not use a trailing slash (my/path not my/path/). No quotes.
|
library. No quotes.
|
||||||
@param maxobs= limit output to the first <code>maxobs</code> observations
|
@param [out] outfile= Optional output file NAME - if provided, then will create
|
||||||
|
a single output file instead of one file per input table.
|
||||||
|
@param [in] maxobs= limit output to the first <code>maxobs</code> observations
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -4037,6 +4047,7 @@ create table &outds (rename=(
|
|||||||
,outloc=%sysfunc(pathname(work)) /* without trailing slash */
|
,outloc=%sysfunc(pathname(work)) /* without trailing slash */
|
||||||
,maxobs=max
|
,maxobs=max
|
||||||
,random_sample=NO
|
,random_sample=NO
|
||||||
|
,outfile=0
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
/* Find the tables */
|
/* Find the tables */
|
||||||
@@ -4048,16 +4059,28 @@ select distinct lowcase(memname)
|
|||||||
from dictionary.tables
|
from dictionary.tables
|
||||||
where upcase(libname)="%upcase(&lib)";
|
where upcase(libname)="%upcase(&lib)";
|
||||||
|
|
||||||
|
/* trim trailing slash, if provided */
|
||||||
|
%let outloc=%mf_trimstr(&outloc,/);
|
||||||
|
%let outloc=%mf_trimstr(&outloc,\);
|
||||||
|
|
||||||
/* create the output directory */
|
/* create the output directory */
|
||||||
%mf_mkdir(&outloc)
|
%mf_mkdir(&outloc)
|
||||||
|
|
||||||
/* create the cards files */
|
/* create the cards files */
|
||||||
%do x=1 %to %sysfunc(countw(&memlist));
|
%do x=1 %to %sysfunc(countw(&memlist));
|
||||||
%let ds=%scan(&memlist,&x);
|
%let ds=%scan(&memlist,&x);
|
||||||
%mp_ds2cards(base_ds=&lib..&ds
|
%mp_ds2cards(base_ds=&lib..&ds
|
||||||
,cards_file="&outloc/&ds..sas"
|
,maxobs=&maxobs
|
||||||
,maxobs=&maxobs
|
,random_sample=&random_sample
|
||||||
,random_sample=&random_sample)
|
%if "&outfile" ne "0" %then %do;
|
||||||
|
,append=YES
|
||||||
|
,cards_file="&outloc/&outfile"
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
,append=NO
|
||||||
|
,cards_file="&outloc/&ds..sas"
|
||||||
|
%end;
|
||||||
|
)
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@@ -12278,31 +12301,20 @@ filename &fname1 clear;
|
|||||||
%mend;/**
|
%mend;/**
|
||||||
@file mv_getgroups.sas
|
@file mv_getgroups.sas
|
||||||
@brief Creates a dataset with a list of viya groups
|
@brief Creates a dataset with a list of viya groups
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details First, load the macros:
|
||||||
|
|
||||||
Using the macros here:
|
|
||||||
|
|
||||||
filename mc url
|
filename mc url
|
||||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||||
%inc mc;
|
%inc mc;
|
||||||
|
|
||||||
An administrator needs to set you up with an access code:
|
Next, execute:
|
||||||
|
|
||||||
%mv_registerclient(outds=client)
|
%mv_getgroups(outds=work.groups)
|
||||||
|
|
||||||
Navigate to the url from the log (opting in to the groups) and paste the
|
@param [in] access_token_var= The global macro variable to contain the access token
|
||||||
access code below:
|
@param [in] grant_type= valid values are "password" or "authorization_code" (unquoted).
|
||||||
|
|
||||||
%mv_tokenauth(inds=client,code=wKDZYTEPK6)
|
|
||||||
|
|
||||||
Now we can run the macro!
|
|
||||||
|
|
||||||
%mv_getgroups()
|
|
||||||
|
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
|
||||||
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
|
||||||
The default is authorization_code.
|
The default is authorization_code.
|
||||||
@param outds= The library.dataset to be created that contains the list of groups
|
@param [out] outds= The library.dataset to be created that contains the list of groups
|
||||||
|
|
||||||
|
|
||||||
@version VIYA V.03.04
|
@version VIYA V.03.04
|
||||||
|
|||||||
@@ -3,25 +3,27 @@
|
|||||||
@brief Create a CARDS file from a SAS dataset.
|
@brief Create a CARDS file from a SAS dataset.
|
||||||
@details Uses dataset attributes to convert all data into datalines.
|
@details Uses dataset attributes to convert all data into datalines.
|
||||||
Running the generated file will rebuild the original dataset.
|
Running the generated file will rebuild the original dataset.
|
||||||
usage:
|
Usage:
|
||||||
|
|
||||||
%mp_ds2cards(base_ds=sashelp.class
|
%mp_ds2cards(base_ds=sashelp.class
|
||||||
, cards_file= "C:\temp\class.sas"
|
, cards_file= "C:\temp\class.sas"
|
||||||
, maxobs=5)
|
, maxobs=5)
|
||||||
|
|
||||||
stuff to add
|
TODO:
|
||||||
- labelling the dataset
|
- labelling the dataset
|
||||||
- explicity setting a unix LF
|
- explicity setting a unix LF
|
||||||
- constraints / indexes etc
|
- constraints / indexes etc
|
||||||
|
|
||||||
@param base_ds= Should be two level - eg work.blah. This is the table that
|
@param [in] base_ds= Should be two level - eg work.blah. This is the table that
|
||||||
is converted to a cards file.
|
is converted to a cards file.
|
||||||
@param tgt_ds= Table that the generated cards file would create. Optional -
|
@param [in] tgt_ds= Table that the generated cards file would create. Optional -
|
||||||
if omitted, will be same as BASE_DS.
|
if omitted, will be same as BASE_DS.
|
||||||
@param cards_file= Location in which to write the (.sas) cards file
|
@param [out] cards_file= Location in which to write the (.sas) cards file
|
||||||
@param maxobs= to limit output to the first <code>maxobs</code> observations
|
@param [in] maxobs= to limit output to the first <code>maxobs</code> observations
|
||||||
@param showlog= whether to show generated cards file in the SAS log (YES/NO)
|
@param [in] showlog= whether to show generated cards file in the SAS log (YES/NO)
|
||||||
@param outencoding= provide encoding value for file statement (eg utf-8)
|
@param [in] outencoding= provide encoding value for file statement (eg utf-8)
|
||||||
|
@param [in] append= If NO then will rebuild the cards file if it already exists,
|
||||||
|
otherwise will append to it. Used by the mp_lib2cards.sas macro.
|
||||||
|
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@@ -34,6 +36,7 @@
|
|||||||
,random_sample=NO
|
,random_sample=NO
|
||||||
,showlog=YES
|
,showlog=YES
|
||||||
,outencoding=
|
,outencoding=
|
||||||
|
,append=NO
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%local i setds nvars;
|
%local i setds nvars;
|
||||||
|
|
||||||
@@ -46,6 +49,8 @@
|
|||||||
%if (&tgt_ds = ) %then %let tgt_ds=&base_ds;
|
%if (&tgt_ds = ) %then %let tgt_ds=&base_ds;
|
||||||
%if %index(&tgt_ds,.)=0 %then %let tgt_ds=WORK.%scan(&base_ds,2,.);
|
%if %index(&tgt_ds,.)=0 %then %let tgt_ds=WORK.%scan(&base_ds,2,.);
|
||||||
%if ("&outencoding" ne "") %then %let outencoding=encoding="&outencoding";
|
%if ("&outencoding" ne "") %then %let outencoding=encoding="&outencoding";
|
||||||
|
%if ("&append" = "") %then %let append=;
|
||||||
|
%else %let append=mod;
|
||||||
|
|
||||||
/* get varcount */
|
/* get varcount */
|
||||||
%let nvars=0;
|
%let nvars=0;
|
||||||
@@ -172,7 +177,7 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &cards_file. &outencoding lrecl=32767 termstr=nl;
|
file &cards_file. &outencoding lrecl=32767 termstr=nl &append;
|
||||||
length __attrib $32767;
|
length __attrib $32767;
|
||||||
if _n_=1 then do;
|
if _n_=1 then do;
|
||||||
put '/*******************************************************************';
|
put '/*******************************************************************';
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
/**
|
/**
|
||||||
@file
|
@file
|
||||||
@brief Convert all library members to CARDS files
|
@brief Convert all library members to CARDS files
|
||||||
@details Gets list of members then calls the <code>%mp_ds2cards()</code>
|
@details Gets list of members then calls the <code>%mp_ds2cards()</code> macro.
|
||||||
macro
|
Usage:
|
||||||
usage:
|
|
||||||
|
|
||||||
%mp_lib2cards(lib=sashelp
|
%mp_lib2cards(lib=sashelp
|
||||||
, outloc= C:\temp )
|
, outloc= C:\temp )
|
||||||
|
|
||||||
|
The output will be one cards file in the `outloc` directory per dataset in the
|
||||||
|
input `lib` library. If the `outloc` directory does not exist, it is created.
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mf_mkdir.sas
|
@li mf_mkdir.sas
|
||||||
|
@li mf_trimstr.sas
|
||||||
@li mp_ds2cards.sas
|
@li mp_ds2cards.sas
|
||||||
|
|
||||||
@param lib= Library in which to convert all datasets
|
@param [in] lib= Library in which to convert all datasets
|
||||||
@param outloc= Location in which to store output. Defaults to WORK library.
|
@param [out] outloc= Location in which to store output. Defaults to WORK
|
||||||
Do not use a trailing slash (my/path not my/path/). No quotes.
|
library. No quotes.
|
||||||
@param maxobs= limit output to the first <code>maxobs</code> observations
|
@param [out] outfile= Optional output file NAME - if provided, then will create
|
||||||
|
a single output file instead of one file per input table.
|
||||||
|
@param [in] maxobs= limit output to the first <code>maxobs</code> observations
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -25,6 +30,7 @@
|
|||||||
,outloc=%sysfunc(pathname(work)) /* without trailing slash */
|
,outloc=%sysfunc(pathname(work)) /* without trailing slash */
|
||||||
,maxobs=max
|
,maxobs=max
|
||||||
,random_sample=NO
|
,random_sample=NO
|
||||||
|
,outfile=0
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
/* Find the tables */
|
/* Find the tables */
|
||||||
@@ -36,16 +42,28 @@ select distinct lowcase(memname)
|
|||||||
from dictionary.tables
|
from dictionary.tables
|
||||||
where upcase(libname)="%upcase(&lib)";
|
where upcase(libname)="%upcase(&lib)";
|
||||||
|
|
||||||
|
/* trim trailing slash, if provided */
|
||||||
|
%let outloc=%mf_trimstr(&outloc,/);
|
||||||
|
%let outloc=%mf_trimstr(&outloc,\);
|
||||||
|
|
||||||
/* create the output directory */
|
/* create the output directory */
|
||||||
%mf_mkdir(&outloc)
|
%mf_mkdir(&outloc)
|
||||||
|
|
||||||
/* create the cards files */
|
/* create the cards files */
|
||||||
%do x=1 %to %sysfunc(countw(&memlist));
|
%do x=1 %to %sysfunc(countw(&memlist));
|
||||||
%let ds=%scan(&memlist,&x);
|
%let ds=%scan(&memlist,&x);
|
||||||
%mp_ds2cards(base_ds=&lib..&ds
|
%mp_ds2cards(base_ds=&lib..&ds
|
||||||
,cards_file="&outloc/&ds..sas"
|
,maxobs=&maxobs
|
||||||
,maxobs=&maxobs
|
,random_sample=&random_sample
|
||||||
,random_sample=&random_sample)
|
%if "&outfile" ne "0" %then %do;
|
||||||
|
,append=YES
|
||||||
|
,cards_file="&outloc/&outfile"
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
,append=NO
|
||||||
|
,cards_file="&outloc/&ds..sas"
|
||||||
|
%end;
|
||||||
|
)
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
Reference in New Issue
Block a user