Here's one way to work around this
data have1;
infile datalines dsd dlm=",";
input subj $ treatment $ painlvl bodypart $;
datalines;
001, A, 2, leg
002, B, 1, head
003, A, 1, arm
004, B, 1, eye
005, B, 2, mouth
;
run; * choose distinct subjects with highest severity (if more than one instance);
/*
2 treatment groups (A or B)
3 levels of pain, 1=low, 2=medium, 3=high
*/
%macro howMany(pain, dsnout);
proc freq data=have1 noprint;
where painlvl=&pain;
table treatment/ out=count;
run;
data a;
set count ;
count_percent=strip(put(count,32.))||" (" || strip(put(percent, 32.2))||")";
run;
proc transpose data=a out=&dsnout (drop= _name_);
id treatment;
var count_percent;
run;
/* Set macro variable emptyDS to N */
/* Assuming the dataset &dsnout has observations at this point */
%let emptyDS=N ;
/* Datastep checks if &dsnout has observations using the ATTRN function */
/* If it doesn't have observations then flip macro varible emptyDS to Y */
data _null_ ;
dsid=open("&dsnout") ;
obsOrVars=attrn(dsid,"ANY") ;
if obsOrVars ne 1 then
call symput("emptyDS","Y") ;
dsid=close(dsid) ;
run ;
/* Check value of macro variable emptyDS */
/* If it is Y (an empty dataset) then */
/* create dataset with observations */
%if &emptyDS=Y %then %do ;
data &dsnout ;
a="0" ;
b="0" ;
output ;
run ;
%end ;
/*
data _empty; * if the data set is empty, how do i output this?;
infile datalines dsd dlm=",";
input a $ b $;
datalines;
0, 0
;
run;
*/
%mend howMANY;
%howMANY(1, _rowa);
%howMANY(2, _rowb);
%howMANY(3, _rowc);
data finished; set _row:;
run;
... View more