Prüfling: generate.sas
Testabdeckung: 100%

Color Legend:
dummy Text
  Abgedeckter Quelltext
  Nicht abgedeckter Quelltext
  Kommentare
  Quelltext der von der Option MCOVERAGE als nicht abgedeckt markiert wurde


RowNumberOut pgmSourceColumn
00001 /**
00002 \file
00003 \ingroup SASUNIT_EXAMPLES_PGM
00004
00005 \brief partition a SAS dataset by groups, one data set per group
00006
00007 By values and number of observations are written to data set labels
00008
00009 Example for the application of assertLibrary.sas, see generate_test.sas.
00010
00011 \version \$Revision: 315 $
00012 \author \$Author: klandwich $
00013 \date \$Date: 2014-02-28 10:25:18 +0100 (Fr, 28 Feb 2014) $
00014 \sa For further information please refer to SASUnit User's Guide
00015 \sa \$HeadURL: https://svn.code.sf.net/p/sasunit/code/trunk/example/saspgm/generate.sas $
00016 \copyright Copyright 2010, 2012 HMS Analytical Software GmbH.
00017 This file is part of SASUnit, the Unit testing framework for SAS(R) programs.
00018 For terms of usage under the GPL license see included file readme.txt
00019 or https://sourceforge.net/p/sasunit/wiki/readme.v1.2/.
00020
00021 \param data input data set
00022 \param by by variable(s) for partitioning
00023 \param out prefix for putput data sets, mubers will be appended
00024 */ /** \cond */
00025
00026 %MACRO generate(
00027 data =
00028 ,by =
00029 ,out =
00030 );
00031
00032 /*-- create local data sets and symbols --------------------------------------*/
00033 %local d_temp1 d_temp2;
00034 data; run; %let d_temp1=&syslast;
00035 data; run; %let d_temp2=&syslast;
00036 %local i count bycount;
00037
00038 /*-- sort input data set and check parameters --------------------------------*/
00039 proc sort data=&data out=&d_temp1;
00040 by &by;
00041 run;
00042 %if &syserr %then %do;
00043 %put ERROR: Macro Generate: data= or by= specified incorrectly;
00044 %return;
00045 %end;
00046
00047 /*-- determine groups --------------------------------------------------------*/
00048 proc means noprint data=&d_temp1(keep=&by);
00049 by &by;
00050 output out=&d_temp2;
00051 run;
00052
00053 data _null_;
00054 set &d_temp2 nobs=count;
00055 call symput ("count", compress(put(count,8.)));
00056 stop;
00057 run;
00058 %do i=1 %to &count;
00059 %local label&i;
00060 %end;
00061
00062 /*-- create data set labels --------------------------------------------------*/
00063 data _null_;
00064 set &d_temp2 end=eof;
00065 array t(1) $ 200 _temporary_;
00066 t(1) = 'Dataset for';
00067 %let i=1;
00068 %do %while(%scan(&by,&i) ne %str());
00069 %if &i>1 %then %do;
00070 t(1) = trim(t(1)) !! ',';
00071 %end;
00072 t(1) = trim(t(1)) !! " %scan(&by,&i)=" !! trim(left(vvalue(%scan(&by,&i))));
00073 %let i = %eval(&i+1);
00074 %end;
00075 %let bycount=%eval(&i-1);
00076 t(1) = trim(t(1)) !! ' (' !! compress(put(_freq_,8.)) !! ' observations)';
00077 call symput ('label' !! compress(put(_n_,8.)), trim(t(1)));
00078 run;
00079
00080 /*-- create output data sets -------------------------------------------------*/
00081 data %do i=1 %to &count; &out&i (label="&&label&i") %end; ;
00082 set &d_temp1;
00083 by &by;
00084 array t(1) _temporary_;
00085 if first.%scan(&by,&bycount) then t(1)+1;
00086 select(t(1));
00087 %do i=1 %to &count;
00088 when(&i) output &out&i;
00089 %end;
00090 end;
00091 run;
00092
00093 proc datasets lib=work nolist;
00094 delete %scan(&d_temp1,2,.) %scan(&d_temp2,2,.);
00095 quit;
00096 %MEND generate;
00097 /** \endcond */


Erzeugt am Freitag, 21. März 2014, 11:39:31 von SASUnit SASUnit Version 1.3.0 (320)