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

Compare commits

..

6 Commits

Author SHA1 Message Date
^
3bb632d60d feat: new mx_getgroups.sas macro for cross-platform use 2024-04-11 11:58:45 +01:00
Allan Bowe
bdd348483c Merge pull request #372 from sasjs/issue371
Issue371
2024-02-23 10:29:25 +00:00
github-actions
92f575551d chore: updating all.sas 2024-02-23 10:26:33 +00:00
^
e616bc940f fix: partial short numeric support in mp_ds2csv 2024-02-23 10:26:01 +00:00
Allan Bowe
b7bca48129 Merge pull request #370 from sasjs/dependabot/npm_and_yarn/follow-redirects-1.15.4
chore(deps): bump follow-redirects from 1.15.2 to 1.15.4
2024-02-19 12:48:34 +00:00
dependabot[bot]
6a2dcbb23f chore(deps): bump follow-redirects from 1.15.2 to 1.15.4
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.2 to 1.15.4.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.2...v1.15.4)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-10 10:19:46 +00:00
7 changed files with 400 additions and 53 deletions

11
all.sas
View File

@@ -5541,13 +5541,21 @@ data _null_;
header = cats(coalescec(varlabel(dsid,i),varnm),dlm); header = cats(coalescec(varlabel(dsid,i),varnm),dlm);
%end; %end;
%else %if &headerformat=SASJS %then %do; %else %if &headerformat=SASJS %then %do;
if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.'); vlen=varlen(dsid,i);
if vartype(dsid,i)='C' then header=cats(varnm,':$char',vlen,'.');
else do; else do;
vfmt=coalescec(varfmt(dsid,i),'0'); vfmt=coalescec(varfmt(dsid,i),'0');
fmttype=mcf_getfmttype(vfmt); fmttype=mcf_getfmttype(vfmt);
if fmttype='DATE' then header=cats(varnm,':date9.'); if fmttype='DATE' then header=cats(varnm,':date9.');
else if fmttype='DATETIME' then header=cats(varnm,':E8601DT26.6'); else if fmttype='DATETIME' then header=cats(varnm,':E8601DT26.6');
else if fmttype='TIME' then header=cats(varnm,':TIME12.'); else if fmttype='TIME' then header=cats(varnm,':TIME12.');
/**
* there is not much point importing a short length numeric like this,
* eg with best4., as the resulting variable will still be stored as
* length 8. We need a length or format statement to ensure variable
* is creatd with the smaller length...
**/
else if vlen<8 then header=cats(varnm,':best',vlen,'.');
else header=cats(varnm,':best.'); else header=cats(varnm,':best.');
end; end;
%end; %end;
@@ -5574,6 +5582,7 @@ data _null_;
set &ds end=last; set &ds end=last;
%do i=1 %to &vcnt; %do i=1 %to &vcnt;
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%local vlen&i;
%if %mf_getvartype(&ds,&var)=C %then %do; %if %mf_getvartype(&ds,&var)=C %then %do;
%let dsv1=%mf_getuniquename(prefix=csvcol1_); %let dsv1=%mf_getuniquename(prefix=csvcol1_);
%let dsv2=%mf_getuniquename(prefix=csvcol2_); %let dsv2=%mf_getuniquename(prefix=csvcol2_);

View File

@@ -118,13 +118,21 @@ data _null_;
header = cats(coalescec(varlabel(dsid,i),varnm),dlm); header = cats(coalescec(varlabel(dsid,i),varnm),dlm);
%end; %end;
%else %if &headerformat=SASJS %then %do; %else %if &headerformat=SASJS %then %do;
if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.'); vlen=varlen(dsid,i);
if vartype(dsid,i)='C' then header=cats(varnm,':$char',vlen,'.');
else do; else do;
vfmt=coalescec(varfmt(dsid,i),'0'); vfmt=coalescec(varfmt(dsid,i),'0');
fmttype=mcf_getfmttype(vfmt); fmttype=mcf_getfmttype(vfmt);
if fmttype='DATE' then header=cats(varnm,':date9.'); if fmttype='DATE' then header=cats(varnm,':date9.');
else if fmttype='DATETIME' then header=cats(varnm,':E8601DT26.6'); else if fmttype='DATETIME' then header=cats(varnm,':E8601DT26.6');
else if fmttype='TIME' then header=cats(varnm,':TIME12.'); else if fmttype='TIME' then header=cats(varnm,':TIME12.');
/**
* there is not much point importing a short length numeric like this,
* eg with best4., as the resulting variable will still be stored as
* length 8. We need a length or format statement to ensure variable
* is creatd with the smaller length...
**/
else if vlen<8 then header=cats(varnm,':best',vlen,'.');
else header=cats(varnm,':best.'); else header=cats(varnm,':best.');
end; end;
%end; %end;
@@ -151,6 +159,7 @@ data _null_;
set &ds end=last; set &ds end=last;
%do i=1 %to &vcnt; %do i=1 %to &vcnt;
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%local vlen&i;
%if %mf_getvartype(&ds,&var)=C %then %do; %if %mf_getvartype(&ds,&var)=C %then %do;
%let dsv1=%mf_getuniquename(prefix=csvcol1_); %let dsv1=%mf_getuniquename(prefix=csvcol1_);
%let dsv2=%mf_getuniquename(prefix=csvcol2_); %let dsv2=%mf_getuniquename(prefix=csvcol2_);

274
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
/**
@file
@brief Testing mp_ds2csv.sas macro
<h4> SAS Macros </h4>
@li mp_ds2csv.sas
@li mp_assert.sas
@li mp_assertscope.sas
**/
data work.shortnum;
length a 3 b 4 c 8;
a=1;b=2;c=3;
output;
stop;
run;
/**
* Test 1 - default CSV
*/
%mp_ds2csv(work.shortnum,outfile="&sasjswork/test1.csv",headerformat=SASJS)
%let test1b=FAIL;
data _null_;
infile "&sasjswork/test1.csv";
input;
list;
if _n_=1 then call symputx('test1a',_infile_);
else if _infile_=:'1,2,3' then call symputx('test1b','PASS');
run;
%mp_assert(
iftrue=("&test1a"="A:best3. B:best4. C:best."),
desc=Checking header row Test 1,
outds=work.test_results
)
%mp_assert(
iftrue=("&test1b"="PASS"),
desc=Checking data row Test 1,
outds=work.test_results
)

View File

@@ -0,0 +1,31 @@
/**
@file
@brief Testing mx_getgroups.test.sas macro
Be sure to run <code>%let mcTestAppLoc=/Public/temp/macrocore;</code> when
running in Studio
<h4> SAS Macros </h4>
@li mf_nobs.sas
@li mf_getuser.sas
@li mp_assert.sas
@li mx_getgroups.sas
**/
%mx_getgroups(outds=work.test1)
%mp_assert(
iftrue=(%mf_nobs(work.test1)>0),
desc=groups were found,
outds=work.test_results
)
%mx_getgroups(outds=work.test2,user=%mf_getuser())
%mp_assert(
iftrue=(%mf_nobs(work.test2)>0),
desc=groups for current user were found,
outds=work.test_results
)

View File

@@ -0,0 +1,83 @@
/**
@file
@brief Fetches all groups or the groups for a particular member
@details When building applications that run on multiple flavours of SAS, it
is convenient to use a single macro (like this one) to fetch the groups
regardless of the flavour of SAS being used
The alternative would be to compile a generic macro in target-specific
folders (SASVIYA, SAS9 and SASJS). This avoids compiling unnecessary macros
at the expense of a more complex sasjsconfig.json setup.
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
@param [in] user= (0) Provide the username on which to filter
@param [in] uid= (0) Provide the userid on which to filter
@param [in] repo= (foundation) SAS9 only, choose the metadata repo to query
@param [in] access_token_var= (ACCESS_TOKEN) VIYA only.
The global macro variable to contain the access token
@param [in] grant_type= (sas_services) VIYA only.
Valid values are "password" or "authorization_code" (unquoted).
@param [out] outds= (work.mx_getgroups) This output dataset will contain the
list of groups. Format:
|NAME:$32.|DESCRIPTION:$256.|GROUPID:best.|
|---|---|---|
|`SomeGroup `|`A group `|`1`|
|`Another Group`|`this is a different group`|`2`|
|`admin`|`Administrators `|`3`|
<h4> SAS Macros </h4>
@li mf_getplatform.sas
@li mm_getgroups.sas
@li ms_getgroups.sas
@li mv_getgroups.sas
@li mv_getusergroups.sas
**/
%macro mx_getgroups(
mdebug=0,
user=0,
uid=0,
repo=foundation,
access_token_var=ACCESS_TOKEN,
grant_type=sas_services,
outds=work.mx_getgroups
)/*/STORE SOURCE*/;
%local platform name shortloc;
%let platform=%mf_getplatform();
%if &platform=SASJS %then %do;
%ms_getgroups(
user=&user,
uid=&uid,
outds=&outds,
mdebug=&mdebug
)
%end;
%else %if &platform=SAS9 or &platform=SASMETA %then %do;
%if &user=0 %then %let user=;
%mm_getGroups(
user=&user
,outds=&outds
,repo=&repo
,mDebug=&mdebug
)
%end;
%else %if &platform=SASVIYA %then %do;
%if &user=0 %then %do;
%mv_getgroups(access_token_var=&access_token_var
,grant_type=&grant_type
,outds=&outds
)
%end;
%else %do;
%mv_getusergroups(&user
,outds=&outds
,access_token_var=&access_token_var
,grant_type=&grant_type
)
%end;
%end;
%mend mx_getgroups;