The script uses the `sashelp.class` dataset by default. This dataset is internal to SAS and always available.
1 Code Block
MACRO
Explanation : This block defines and calls a `%defaults` macro. This macro checks for the existence of the macro variable `dset`. If `dset` does not exist, it declares it global and initializes it with the path `sashelp.class`.
Copied!
%macro defaults ;
%* these defaults may be passed in, or else they default ;
%if %symexist(dset)=0 %then %do;
%global dset;
%let dset=sashelp.class;
%end;
%mend defaults;
%defaults
1
%macro defaults ;
2
%* these defaults may be passed in, or ELSE they default ;
3
%IF %symexist(dset)=0 %THEN %DO;
4
%global dset;
5
%let dset=sashelp.class;
6
%END;
7
%mend defaults;
8
%defaults
2 Code Block
DATA STEP
Explanation : This `DATA _NULL_` step-by-step opens the dataset specified by `&dset` (by default `sashelp.class`), retrieves the number of observations (`nobs`) via the `attrn` function, and stores it in a macro variable named `nobs` using `call symput`.
Copied!
data _null_ ;
dsid=open("&dset");
nobs=attrn(dsid,'nobs');
call symput('nobs',strip(put(nobs,8.)));
run;
1
DATA _null_ ;
2
dsid=open("&dset");
3
nobs=attrn(dsid,'nobs');
4
call symput('nobs',strip(put(nobs,8.)));
5
RUN;
3 Code Block
DATA STEP Data
Explanation : This block generates an XML file. It first retrieves the path to the working directory (`work`) and stores it in the `pathname` macro variable. An `xml` type libname `test` is then assigned to a `temp.xml` file in this directory. The content of the `&dset` dataset is copied into `test.test`, thus creating the XML file. The libname is then freed. Finally, a `DATA _NULL_` reads the `temp.xml` file and displays its content directly via `_webout`.
Copied!
%let pathname=%sysfunc(pathname(work)) ;
libname test xml "&pathname/temp.xml" ;
data test.test ;
set &dset ;
run ;
libname test ;
data _null_ ;
infile "&pathname/temp.xml" ;
file _webout ;
input ;
put _infile_ ;
run ;
1
%let pathname=%sysfunc(pathname(work)) ;
2
LIBNAME test xml "&pathname/temp.xml" ;
3
DATA test.test ;
4
SET &dset ;
5
RUN ;
6
LIBNAME test ;
7
DATA _null_ ;
8
INFILE"&pathname/temp.xml" ;
9
file _webout ;
10
INPUT ;
11
put _infile_ ;
12
RUN ;
4 Code Block
MACRO
Explanation : These lines define the delimiters for a SAS stored process. `%STPBEGIN` and `%STPEND` enclose the code that will be executed as part of the stored process. The line `*';*\"*/;run;` is standard syntax for potentially terminating pending code blocks or statements, often used to ensure clean execution within the context of stored processes.
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.