Attention : This code requires administrator privileges.
The script begins by creating two temporary directories (`&sasjswork/path1` and `&sasjswork/path2`) using the `mf_mkdir` macro, then associates them with `libname`s (path1, path2). It then defines the same `whichpath` format in these two libraries, but with distinct output values ('path1' and 'path2' respectively). Two scenarios are tested: the first where `path1` has priority in `FMTSEARCH`, and the second where `path2` has priority. In each scenario, a `DATA _NULL_` step is used to apply the format to the value 0 and store the result in a macro variable (`test1` or `test2`). The `mp_assert` macro is called to verify that the correct format (that of the priority library) has been applied. The `mp_getformats` macro is then executed to extract the details of the `WHICHPATH` format into output datasets (`detail1` or `detail2`), and the results (notably the label associated with 'OTHER') are again verified with `mp_assert` to ensure that the detailed information matches the version of the format found.
Data Analysis
Type : CREATION_INTERNE
The main data processed by this script (the SAS formats named `whichpath`) are created and defined directly in the script via `PROC FORMAT`. No external data or data from standard SAS libraries is used as input for the format testing process. Temporary datasets are created by the `mp_getformats` (`sum`, `detail1`, `detail2`) and `mp_assert` (`work.test_results`) macros to store the test results and detailed format information.
1 Code Block
Appel Macro
Explanation : These lines call the `mf_mkdir` macro to create two temporary directories: `path1` and `path2` within the location defined by the macro variable `&sasjswork`. These directories will serve as libraries to store SAS formats.
Explanation : Two SAS libraries, `path1` and `path2`, are defined and associated respectively with the physical directories `&sasjswork/path1` and `&sasjswork/path2` created previously. These libraries will be used to register and search for SAS formats.
Explanation : This block defines a SAS format named `whichpath` in each of the two libraries `path1` and `path2`. Each definition assigns the value '0' to a specific label ('path1' or 'path2') and a generic label ('big fat problem if not path1/path2') to all other values. This allows testing which version of the format is used depending on the `FMTSEARCH` configuration.
Copied!
PROC FORMAT library=path1;
value whichpath 0 = 'path1' other='big fat problem if not path1';
PROC FORMAT library=path2;
value whichpath 0 = 'path2' other='big fat problem if not path2';
RUN;
1
PROC FORMAT library=path1;
2
value whichpath 0 = 'path1' other='big fat problem if not path1';
3
PROC FORMAT library=path2;
4
value whichpath 0 = 'path2' other='big fat problem if not path2';
5
RUN;
4 Code Block
Options / DATA STEP / Appel Macro
Explanation : This block configures the first test scenario. The `FMTSEARCH` option is set to search for formats first in `path1`, then in `path2`. A `DATA _NULL_` step is used to apply the `whichpath` format to the value `0` and store the result in the macro variable `test1`. The `mp_assert` macro verifies that the expected value is 'path1'. Then, the `mp_getformats` macro is called to extract the details of the `WHICHPATH` format into the `detail1` dataset. A second `DATA _NULL_` step reads this dataset to retrieve the label associated with '**OTHER**' and stores it in `tst1`. A final `mp_assert` validates that this label matches the one defined in `path1`.
Copied!
options insert=(fmtsearch=(path1 path2));
data _null_;
test=0;
call symputx('test1',put(test,whichpath.));
run;
%mp_assert(
iftrue=("&test1"="path1"),
desc=Check correct format is applied,
outds=work.test_results
)
%mp_getformats(fmtlist=WHICHPATH,outsummary=sum,outdetail=detail1)
%let tst1=0;
data _null_;
set detail1;
if fmtname='WHICHPATH' and start='**OTHER**' then call symputx('tst1',label);
putlog (_all_)(=);
run;
%mp_assert(
iftrue=("&tst1"="big fat problem if not path1"),
desc=Check correct detail results are applied,
outds=work.test_results
)
IF fmtname='WHICHPATH' and start='**OTHER**'THEN call symputx('tst1',label);
16
putlog (_all_)(=);
17
RUN;
18
%mp_assert(
19
iftrue=("&tst1"="big fat problem if not path1"),
20
desc=Check correct detail results are applied,
21
outds=work.test_results
22
)
5 Code Block
Options / DATA STEP / Appel Macro
Explanation : This block executes the second test scenario, similar to the previous one, but with a reversed order for `FMTSEARCH` (`path2` then `path1`). The same verification steps are performed: application of the format in a `DATA _NULL_` step, validation of the result with `mp_assert` to ensure that the value this time is 'path2'. Then, `mp_getformats` extracts the format details into `detail2`, and a final `mp_assert` verifies that the '**OTHER**' label matches the one defined in `path2`.
Copied!
options insert=(fmtsearch=(path2 path1));
data _null_;
test=0;
call symputx('test2',put(test,whichpath.));
run;
%mp_assert(
iftrue=("&test2"="path2"),
desc=Check correct format is applied,
outds=work.test_results
)
%mp_getformats(fmtlist=WHICHPATH,outsummary=sum,outdetail=detail2)
%let tst2=0;
data _null_;
set detail2;
if fmtname='WHICHPATH' and start='**OTHER**' then call symputx('tst2',label);
putlog (_all_)(=);
run;
%mp_assert(
iftrue=("&tst2"="big fat problem if not path2"),
desc=Check correct detail results are applied,
outds=work.test_results
)
IF fmtname='WHICHPATH' and start='**OTHER**'THEN call symputx('tst2',label);
16
putlog (_all_)(=);
17
RUN;
18
%mp_assert(
19
iftrue=("&tst2"="big fat problem if not path2"),
20
desc=Check correct detail results are applied,
21
outds=work.test_results
22
)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de This file is part of SASUnit, the Unit testing framework for SAS(R) programs. For copyright information and terms of usage under the GNU Lesser General Public License see included file README.md or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.