1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-08 18:00:06 +00:00

Compare commits

...

7 Commits

Author SHA1 Message Date
Allan Bowe
a08f6aeea2 Merge pull request #135 from sasjs/abortfix
fix: removing 'Log Extract' from abort MSG in mp_abort when not capturing the log
2021-12-29 14:54:01 +02:00
munja
469bd574ac fix: removing 'Log Extract' from abort MSG in mp_abort when not capturing the log 2021-12-29 12:35:25 +00:00
Allan Bowe
c41918c0a8 Merge pull request #134 from sasjs/fmtfix
fix: preventing error when mp_applyformats has no formats to apply
2021-12-29 14:19:59 +02:00
munja
0361ca574d fix: preventing error when mp_applyformats has no formats to apply 2021-12-29 12:19:34 +00:00
Allan Bowe
c75c169b80 Merge pull request #133 from sasjs/fmtname
fix: adding fmtname to mp_getcols() macro
2021-12-28 15:39:07 +02:00
munja
eac47bd5db fix: adding fmtname to mp_getcols() macro 2021-12-28 13:25:53 +00:00
munja
d302ef266d chore: doc page formatting & content 2021-12-27 11:54:46 +00:00
8 changed files with 127 additions and 104 deletions

45
all.sas
View File

@@ -2135,8 +2135,8 @@ Usage:
%if %symexist(SYSPRINTTOLOG) %then %let logloc=&SYSPRINTTOLOG; %if %symexist(SYSPRINTTOLOG) %then %let logloc=&SYSPRINTTOLOG;
%else %let logloc=%qsysfunc(getoption(LOG)); %else %let logloc=%qsysfunc(getoption(LOG));
proc printto log=log;run; proc printto log=log;run;
%if %length(&logloc)>0 %then %do;
%let logline=0; %let logline=0;
%if %length(&logloc)>0 %then %do;
data _null_; data _null_;
infile &logloc lrecl=5000; infile &logloc lrecl=5000;
input; putlog _infile_; input; putlog _infile_;
@@ -2185,7 +2185,10 @@ Usage:
file _webout mod lrecl=32000 encoding='utf-8'; file _webout mod lrecl=32000 encoding='utf-8';
length msg $32767 ; length msg $32767 ;
sasdatetime=datetime(); sasdatetime=datetime();
msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg')); msg=symget('msg');
%if &logline>0 %then %do;
msg=cats(msg,'\n\nLog Extract:\n',symget('logmsg'));
%end;
/* escape the quotes */ /* escape the quotes */
msg=tranwrd(msg,'"','\"'); msg=tranwrd(msg,'"','\"');
/* ditch the CRLFs as chrome complains */ /* ditch the CRLFs as chrome complains */
@@ -2478,16 +2481,16 @@ run;
proc sql noprint; proc sql noprint;
select distinct lib into: liblist separated by ' ' from &inds; select distinct lib into: liblist separated by ' ' from &inds;
%put &=liblist; %put &=liblist;
%do i=1 %to %sysfunc(countw(&liblist)); %if %length(&liblist)>0 %then %do i=1 %to %sysfunc(countw(&liblist));
%let lib=%scan(&liblist,1); %let lib=%scan(&liblist,1);
%let engine=%mf_getengine(&lib); %let engine=%mf_getengine(&lib);
%if &engine ne V9 and &engine ne BASE %then %do; %if &engine ne V9 and &engine ne BASE %then %do;
%let msg=&lib has &engine engine - formats cannot be applied; %let msg=&lib has &engine engine - formats cannot be applied;
proc sql;
insert into &outds set lib="&lib",ds="_all_",var="_all", msg="&msg" ; insert into &outds set lib="&lib",ds="_all_",var="_all", msg="&msg" ;
%if &errds=0 %then %put %str(ERR)OR: &msg; %if &errds=0 %then %put %str(ERR)OR: &msg;
%end; %end;
%end; %end;
quit;
%if %mf_nobs(&outds)>0 %then %return; %if %mf_nobs(&outds)>0 %then %return;
@@ -5539,11 +5542,11 @@ filename &fref1 clear;
@param ds The dataset from which to obtain column metadata @param ds The dataset from which to obtain column metadata
@param outds= (work.cols) The output dataset to create. Sample data: @param outds= (work.cols) The output dataset to create. Sample data:
|NAME $|LENGTH 8|VARNUM 8|LABEL $|FORMAT $49|TYPE $1 |DDTYPE $| |NAME:$32.|LENGTH:best.|VARNUM:best.|LABEL:$256.|FMTNAME:$32.|FORMAT:$49.|TYPE:$1.|DDTYPE:$9.|
|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|---|
|AIR|8|2|international airline travel (thousands)|8.|N|NUMERIC| |`AIR `|`8 `|`2 `|`international airline travel (thousands) `|` `|`8. `|`N `|`NUMERIC `|
|DATE|8|1|DATE|MONYY.|N|DATE| |`DATE `|`8 `|`1 `|`DATE `|`MONYY `|`MONYY. `|`N `|`DATE `|
|REGION|3|3|REGION|$3.|C|CHARACTER| |`REGION `|`3 `|`3 `|`REGION `|` `|`$3. `|`C `|`CHARACTER `|
<h4> Related Macros </h4> <h4> Related Macros </h4>
@li mf_getvarlist.sas @li mf_getvarlist.sas
@@ -5555,26 +5558,27 @@ filename &fref1 clear;
**/ **/
%macro mp_getcols(ds, outds=work.cols); %macro mp_getcols(ds, outds=work.cols);
%local dropds;
proc contents noprint data=&ds proc contents noprint data=&ds
out=_data_ (keep=name type length label varnum format:); out=_data_ (keep=name type length label varnum format:);
run; run;
data &outds(keep=name type length varnum format label ddtype); %let dropds=&syslast;
set &syslast(rename=(format=format2 type=type2)); data &outds(keep=name type length varnum format label ddtype fmtname);
set &dropds(rename=(format=fmtname type=type2));
name=upcase(name); name=upcase(name);
if type2=2 then do; if type2=2 then do;
length format $49.; length format $49.;
if format2='' then format=cats('$',length,'.'); if fmtname='' then format=cats('$',length,'.');
else if formatl=0 then format=cats(format2,'.'); else if formatl=0 then format=cats(fmtname,'.');
else format=cats(format2,formatl,'.'); else format=cats(fmtname,formatl,'.');
type='C'; type='C';
ddtype='CHARACTER'; ddtype='CHARACTER';
end; end;
else do; else do;
if format2='' then format=cats(length,'.'); if fmtname='' then format=cats(length,'.');
else if formatl=0 then format=cats(format2,'.'); else if formatl=0 then format=cats(fmtname,'.');
else if formatd=0 then format=cats(format2,formatl,'.'); else if formatd=0 then format=cats(fmtname,formatl,'.');
else format=cats(format2,formatl,'.',formatd); else format=cats(fmtname,formatl,'.',formatd);
type='N'; type='N';
if format=:'DATETIME' or format=:'E8601DT' then ddtype='DATETIME'; if format=:'DATETIME' or format=:'E8601DT' then ddtype='DATETIME';
else if format=:'DATE' or format=:'DDMMYY' or format=:'MMDDYY' else if format=:'DATE' or format=:'DDMMYY' or format=:'MMDDYY'
@@ -5586,7 +5590,8 @@ data &outds(keep=name type length varnum format label ddtype);
end; end;
if label='' then label=name; if label='' then label=name;
run; run;
proc sql;
drop table &dropds;
%mend mp_getcols;/** %mend mp_getcols;/**
@file mp_getconstraints.sas @file mp_getconstraints.sas
@brief Get constraint details at column level @brief Get constraint details at column level

View File

@@ -110,8 +110,8 @@
%if %symexist(SYSPRINTTOLOG) %then %let logloc=&SYSPRINTTOLOG; %if %symexist(SYSPRINTTOLOG) %then %let logloc=&SYSPRINTTOLOG;
%else %let logloc=%qsysfunc(getoption(LOG)); %else %let logloc=%qsysfunc(getoption(LOG));
proc printto log=log;run; proc printto log=log;run;
%if %length(&logloc)>0 %then %do;
%let logline=0; %let logline=0;
%if %length(&logloc)>0 %then %do;
data _null_; data _null_;
infile &logloc lrecl=5000; infile &logloc lrecl=5000;
input; putlog _infile_; input; putlog _infile_;
@@ -160,7 +160,10 @@
file _webout mod lrecl=32000 encoding='utf-8'; file _webout mod lrecl=32000 encoding='utf-8';
length msg $32767 ; length msg $32767 ;
sasdatetime=datetime(); sasdatetime=datetime();
msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg')); msg=symget('msg');
%if &logline>0 %then %do;
msg=cats(msg,'\n\nLog Extract:\n',symget('logmsg'));
%end;
/* escape the quotes */ /* escape the quotes */
msg=tranwrd(msg,'"','\"'); msg=tranwrd(msg,'"','\"');
/* ditch the CRLFs as chrome complains */ /* ditch the CRLFs as chrome complains */

View File

@@ -142,16 +142,16 @@ run;
proc sql noprint; proc sql noprint;
select distinct lib into: liblist separated by ' ' from &inds; select distinct lib into: liblist separated by ' ' from &inds;
%put &=liblist; %put &=liblist;
%do i=1 %to %sysfunc(countw(&liblist)); %if %length(&liblist)>0 %then %do i=1 %to %sysfunc(countw(&liblist));
%let lib=%scan(&liblist,1); %let lib=%scan(&liblist,1);
%let engine=%mf_getengine(&lib); %let engine=%mf_getengine(&lib);
%if &engine ne V9 and &engine ne BASE %then %do; %if &engine ne V9 and &engine ne BASE %then %do;
%let msg=&lib has &engine engine - formats cannot be applied; %let msg=&lib has &engine engine - formats cannot be applied;
proc sql;
insert into &outds set lib="&lib",ds="_all_",var="_all", msg="&msg" ; insert into &outds set lib="&lib",ds="_all_",var="_all", msg="&msg" ;
%if &errds=0 %then %put %str(ERR)OR: &msg; %if &errds=0 %then %put %str(ERR)OR: &msg;
%end; %end;
%end; %end;
quit;
%if %mf_nobs(&outds)>0 %then %return; %if %mf_nobs(&outds)>0 %then %return;

View File

@@ -14,11 +14,11 @@
@param ds The dataset from which to obtain column metadata @param ds The dataset from which to obtain column metadata
@param outds= (work.cols) The output dataset to create. Sample data: @param outds= (work.cols) The output dataset to create. Sample data:
|NAME $|LENGTH 8|VARNUM 8|LABEL $|FORMAT $49|TYPE $1 |DDTYPE $| |NAME:$32.|LENGTH:best.|VARNUM:best.|LABEL:$256.|FMTNAME:$32.|FORMAT:$49.|TYPE:$1.|DDTYPE:$9.|
|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|---|
|AIR|8|2|international airline travel (thousands)|8.|N|NUMERIC| |`AIR `|`8 `|`2 `|`international airline travel (thousands) `|` `|`8. `|`N `|`NUMERIC `|
|DATE|8|1|DATE|MONYY.|N|DATE| |`DATE `|`8 `|`1 `|`DATE `|`MONYY `|`MONYY. `|`N `|`DATE `|
|REGION|3|3|REGION|$3.|C|CHARACTER| |`REGION `|`3 `|`3 `|`REGION `|` `|`$3. `|`C `|`CHARACTER `|
<h4> Related Macros </h4> <h4> Related Macros </h4>
@li mf_getvarlist.sas @li mf_getvarlist.sas
@@ -30,26 +30,27 @@
**/ **/
%macro mp_getcols(ds, outds=work.cols); %macro mp_getcols(ds, outds=work.cols);
%local dropds;
proc contents noprint data=&ds proc contents noprint data=&ds
out=_data_ (keep=name type length label varnum format:); out=_data_ (keep=name type length label varnum format:);
run; run;
data &outds(keep=name type length varnum format label ddtype); %let dropds=&syslast;
set &syslast(rename=(format=format2 type=type2)); data &outds(keep=name type length varnum format label ddtype fmtname);
set &dropds(rename=(format=fmtname type=type2));
name=upcase(name); name=upcase(name);
if type2=2 then do; if type2=2 then do;
length format $49.; length format $49.;
if format2='' then format=cats('$',length,'.'); if fmtname='' then format=cats('$',length,'.');
else if formatl=0 then format=cats(format2,'.'); else if formatl=0 then format=cats(fmtname,'.');
else format=cats(format2,formatl,'.'); else format=cats(fmtname,formatl,'.');
type='C'; type='C';
ddtype='CHARACTER'; ddtype='CHARACTER';
end; end;
else do; else do;
if format2='' then format=cats(length,'.'); if fmtname='' then format=cats(length,'.');
else if formatl=0 then format=cats(format2,'.'); else if formatl=0 then format=cats(fmtname,'.');
else if formatd=0 then format=cats(format2,formatl,'.'); else if formatd=0 then format=cats(fmtname,formatl,'.');
else format=cats(format2,formatl,'.',formatd); else format=cats(fmtname,formatl,'.',formatd);
type='N'; type='N';
if format=:'DATETIME' or format=:'E8601DT' then ddtype='DATETIME'; if format=:'DATETIME' or format=:'E8601DT' then ddtype='DATETIME';
else if format=:'DATE' or format=:'DDMMYY' or format=:'MMDDYY' else if format=:'DATE' or format=:'DDMMYY' or format=:'MMDDYY'
@@ -61,5 +62,6 @@ data &outds(keep=name type length varnum format label ddtype);
end; end;
if label='' then label=name; if label='' then label=name;
run; run;
proc sql;
drop table &dropds;
%mend mp_getcols; %mend mp_getcols;

View File

@@ -1,6 +1,6 @@
{ {
"name": "@sasjs/core", "name": "@sasjs/core",
"description": "Production Ready Macros for SAS Application Developers", "description": "Macros for SAS Application Developers",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
"SAS", "SAS",

View File

@@ -1,15 +1,21 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- HTML header for doxygen 1.8.17--> <!-- HTML header for doxygen 1.8.17-->
<html xmlns="https://www.w3.org/1999/xhtml" lang="en"> <html xmlns="https://www.w3.org/1999/xhtml" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" /> <meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:title" content="MacroCore" />
<meta property="og:url" content="https://core.sasjs.io" />
<meta property="og:image" content="https://core.sasjs.io/Macro_core_website_1.png" />
<meta name="author" content="Allan Bowe"> <meta name="author" content="Allan Bowe">
<meta name="generator" content="Doxygen $doxygenversion" /> <meta name="generator" content="Doxygen $doxygenversion" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<!--BEGIN PROJECT_NAME--> <!--BEGIN PROJECT_NAME-->
<meta name="description" content="$projectbrief" /> <meta name="description" content="$projectbrief" />
<meta name="og:description" content="$projectbrief" />
<!--END PROJECT_NAME--> <!--END PROJECT_NAME-->
<!--BEGIN !PROJECT_NAME--> <!--BEGIN !PROJECT_NAME-->
<title>$title</title> <title>$title</title>
@@ -22,6 +28,7 @@
<link rel="shortcut icon" href="$relpath^favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="$relpath^favicon.ico" type="image/x-icon" />
$extrastylesheet $extrastylesheet
</head> </head>
<body> <body>
<div id="top"> <div id="top">
<!-- do not remove this div, it is closed by doxygen! --> <!-- do not remove this div, it is closed by doxygen! -->
@@ -33,14 +40,12 @@
<tr style="height: 56px"> <tr style="height: 56px">
<!--BEGIN PROJECT_LOGO--> <!--BEGIN PROJECT_LOGO-->
<td id="projectlogo"> <td id="projectlogo">
<a href="$relpath^" <a href="$relpath^"><img alt="Logo" src="$relpath^$projectlogo" /></a>
><img alt="Logo" src="$relpath^$projectlogo"
/></a>
</td> </td>
<!--END PROJECT_LOGO--> <!--END PROJECT_LOGO-->
<td id="projectalign" style="padding-left: 0.5em"> <td id="projectalign" style="padding-left: 0.5em">
<div id="projectbrief"> <div id="projectbrief">
Production Ready Macros for SAS Application Developers<br /> Macros for SAS Application Developers<br />
<a href="https://github.com/sasjs/core"> <a href="https://github.com/sasjs/core">
https://github.com/sasjs/core https://github.com/sasjs/core
</a> </a>
@@ -64,4 +69,5 @@
<!-- end header part --> <!-- end header part -->
</div> </div>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,5 @@
{ {
"$schema": "https://cli.sasjs.io/sasjsconfig-schema.json", "$schema": "https://raw.githubusercontent.com/sasjs/utils/main/src/types/sasjsconfig-schema.json",
"macroFolders": [ "macroFolders": [
"base", "base",
"fcmp", "fcmp",

View File

@@ -4,6 +4,7 @@
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mp_getcols.sas @li mp_getcols.sas
@li mp_assertcols.sas
@li mp_assertcolvals.sas @li mp_assertcolvals.sas
@li mp_assertdsobs.sas @li mp_assertdsobs.sas
@@ -31,3 +32,9 @@ run;
desc=All values have a match, desc=All values have a match,
test=ALLVALS test=ALLVALS
) )
%mp_assertcols(work.info,
cols=name type length varnum format label ddtype fmtname,
test=ALL,
desc=check all columns exist
)