mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 23:50:06 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bb632d60d | ||
|
|
bdd348483c | ||
|
|
92f575551d | ||
|
|
e616bc940f | ||
|
|
b7bca48129 | ||
|
|
6a2dcbb23f |
11
all.sas
11
all.sas
@@ -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_);
|
||||||
|
|||||||
@@ -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
274
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
43
tests/base/mp_ds2csv.test.2.sas
Normal file
43
tests/base/mp_ds2csv.test.2.sas
Normal 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
|
||||||
|
)
|
||||||
31
tests/x-platform/mx_getgroups.test.sas
Normal file
31
tests/x-platform/mx_getgroups.test.sas
Normal 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
|
||||||
|
)
|
||||||
83
xplatform/mx_getgroups.sas
Normal file
83
xplatform/mx_getgroups.sas
Normal 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;
|
||||||
Reference in New Issue
Block a user