Why you should use DOSUBL instead of a macro
( this just redirects you back to this post)
https://goo.gl/s5mqqv
https://communities.sas.com/t5/Base-SAS-Programming/Macro-for-Sum-by-Category/m-p/346050
Last posted solution fails
Splitting sashelp.cars in one dataset per car make.
I realize there are many other more efficient ways to do this(ie hash),
but that is not the point.
REASONS
1. Can stop the submission of code if error in any iteration
2. Encapsulates code in one address space
3. Stored program
4. Theoretically should run much faster(needs development work?)
HAVE meta data car makes in sashelp.cars
=======================================
distinct values of column MAKE in SASHELP.CARS
Acura
Audi
BMW
Buick
Cadillac
Chevrolet
Chrysler
...
Saturn
Scion
Subaru
Suzuki
Toyota
Volkswagen
Volvo
WANT ( create datasets and stop code if the creation of any dataset fails)
============================================================
Solution fails for 'Mercedes-Benz' because a SAS dataset name cannot have a '-';
I want to print this message and stop;
Dataset creation failed for Mercedes-Benz stopping parent
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;,
_DATA_, _LAST_, _NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.MERCEDES may be incomplete. When this step was stopped there were 0
observations and 15 variables.
WARNING: Data set WORK.MERCEDES was not replaced because this step was stopped.
WARNING: The data set WORK.BENZ may be incomplete. When this step was stopped there were 0
observations and 15 variables.
WARNING: Data set WORK.BENZ was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
Dataset creation failed for Mercedes-Benz stopping parent
* _ _ _
___ ___ | |_ _| |_(_) ___ _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|
;
data _null_;
if _n_=0 then do;
%let rc=%sysfunc(dosubl('
Proc sql ;
Select Distinct quote(trim(Make))
into : makes separated by ","
from sashelp.cars
;quit;
'));
end;
* check that proc sql ran;
if &rc then stop;
length make $32;
do make = &makes.;
call symputx('make',make);
rc=dosubl('
data &make;
set sashelp.cars(where=(make="&make"));
run;quit;
%let Errortext= &syserrortext;
%let Errorcode= &syserr;
');
if symget('errorcode') ne "0" then do;
put "dataset creation failed for " make " stopping parent";
stop;
end;
end;
stop;
run;quit;
... View more