The macro operates on external files whose paths or filerefs are provided as parameters (`inloc`, `outloc`, `inref`, `outref`). It does not generate internal data for its own processing but manipulates existing or to-be-created binary files.
1 Code Block
MACRO DEFINITION
Explanation : Definition of the `%mp_binarycopy` macro with its input parameters, including file paths (inloc, outloc), file references (inref, outref), operation mode (CREATE or APPEND) and an execution condition (iftrue). The macro includes a local variable 'mod' and an early exit condition.
Copied!
%macro mp_binarycopy(
inloc= /* full path and filename of the object to be copied */
,outloc= /* full path and filename of object to be created */
,inref=____in /* override default to use own filerefs */
,outref=____out /* override default to use own filerefs */
,mode=CREATE
,iftrue=%str(1=1)
)/*/STORE SOURCE*/;
%local mod;
%if not(%eval(%unquote(&iftrue))) %then %return;
1
%macro mp_binarycopy(
2
inloc= /* full path and filename of the object to be copied */
3
,outloc= /* full path and filename of object to be created */
4
,inref=____in /* override default to use own filerefs */
5
,outref=____out /* override default to use own filerefs */
6
,mode=CREATE
7
,iftrue=%str(1=1)
8
)/*/STORE SOURCE*/;
9
%local mod;
10
11
%IF not(%eval(%unquote(&iftrue))) %THEN %return;
2 Code Block
Pre-processing (Filerefs)
Explanation : This section configures the input and output filerefs. If the `inref` or `outref` parameters have not been overridden, the macro creates temporary filerefs (`____in`, `____out`) pointing to the paths specified by `inloc` and `outloc`. The `lrecl=1048576` option defines the logical record length, and `&mod` is added to the output fileref if the mode is 'APPEND'.
Copied!
%if &mode=APPEND %then %let mod=mod;
/* these IN and OUT filerefs can point to anything */
%if &inref = ____in %then %do;
filename &inref &inloc lrecl=1048576 ;
%end;
%if &outref=____out %then %do;
filename &outref &outloc lrecl=1048576 &mod;
%end;
1
%IF &mode=APPEND %THEN %let mod=mod;
2
3
/* these IN and OUT filerefs can point to anything */
4
%IF &inref = ____in %THEN %DO;
5
filename &inref &inloc lrecl=1048576 ;
6
%END;
7
%IF &outref=____out %THEN %DO;
8
filename &outref &outloc lrecl=1048576 &mod;
9
%END;
3 Code Block
DATA STEP
Explanation : Central block of the macro, using a `DATA _null_` step. It reads the input file (`infile`) byte by byte (`lrecl=1 recfm=n`) and writes each byte directly to the output file (`file`). `sourcechar $char1.` reads a character, `format sourcechar hex2.` formats it as hexadecimal, and `put sourcechar char1.` writes it as a single character, ensuring a binary copy.
Copied!
/* copy the file byte-for-byte */
data _null_;
infile &inref lrecl=1 recfm=n;
file &outref &mod recfm=n;
input sourcechar $char1. @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_2.json;
format sourcechar hex2.;
put sourcechar char1. @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_2.json;
run;
put sourcechar char1. @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_2.json;
8
RUN;
4 Code Block
Post-processing (Filerefs Release)
Explanation : After the copy operation, this section ensures that temporary filerefs (`____in`, `____out`) created by the macro are released (`filename ... clear;`), thus avoiding naming conflicts and unnecessary resource consumption.
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 (c) 2001-2006 Rodney Sparapani
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.