The data processed by the script comes from the standard output of an operating system command (e.g., 'dir' on Windows) executed via `filename pipe`. This data is read and analyzed on the fly by the DATA step.
1 Code Block
MACRO / FILENAME
Explanation : This block defines the beginning of the `%getstats` macro and declares a 'pipe' type fileref `cmd`. This fileref is configured to execute an operating system command (passed as the `dir_cmd` argument) and redirect its output to SAS, allowing SAS to read this output as a file.
Explanation : This `DATA _NULL_` block reads the OS command's output via the `cmd` fileref. It is designed to read the sixth line (`#6`) and extract date (`date`), time (`time`), and size (`size`) values using specific SAS formats. **Warning:** The character strings ` @code_sas_json/...` included in the original code's `input` statement represent a SAS syntax error and would make the script non-functional. The intention was probably to specify numeric column positions (e.g., ` @code_sas_json_prod_multi/10 One to One Merge_de.json date ...`). After reading, `call symput` is used to store these formatted values in the global macro variables `_date`, `_time`, and `_size`.
Copied!
data _null_ ;
infile cmd truncover ;
* This works on windows XP Professional, but on other version you might need to adjust the settings to
read the information you want from different positions ;
input #6 @code_sas_json/L3.13-Storing_a_List_of_Values_in_a_Macro-Variable.json date ddmmyy10.
@code_sas_json/L3.13-Storing_a_List_of_Values_in_a_Macro-Variable.json time time5.
@code_sas_json/q203.json size comma17. ;
* Now write the data to macro variables to be used ;
call symput('_date',put(date,date9.)) ;
call symput('_time',put(time,time5.)) ;
* note we use left justification within formatted field , otherwise number is right justified within field ;
call symput('_size',put(size,comma9. -l)) ;
run ;
1
DATA _null_ ;
2
INFILE cmd truncover ;
3
* This works on windows XP Professional, but on other version you might need to adjust the settings to
4
read the information you want from different positions ;
5
INPUT #6 @code_sas_json/L3.13-Storing_a_List_of_Values_in_a_Macro-Variable.json date ddmmyy10.
6
@code_sas_json/L3.13-Storing_a_List_of_Values_in_a_Macro-Variable.json time time5.
7
@code_sas_json/q203.json size comma17. ;
8
* Now write the data to macro variables to be used ;
9
call symput('_date',put(date,date9.)) ;
10
call symput('_time',put(time,time5.)) ;
11
* note we use left justification within formatted field , otherwise number is right justified within field ;
12
call symput('_size',put(size,comma9. -l)) ;
13
RUN ;
3 Code Block
MACRO
Explanation : This section declares the macro variables `_date`, `_time`, and `_size` as global, making them accessible after the macro execution. `%mend getstats` marks the end of the macro definition.
Copied!
%global _date _time _size ;
%mend getstats ;
1
%global _date _time _size ;
2
%mend getstats ;
4 Code Block
MACRO CALL / %PUT
Explanation : This block calls the `%getstats` macro, providing it with the system command `dir c:\windows\notepad.exe`. This executes the command and updates the macro variables. Then, the `%put` statement is used to display the final values of `_date`, `_time`, and `_size` in the SAS log.
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.
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.