下面是在excel中获取报告的一小段代码。
%if &linear %then %do;
ods excel options(sheet_name="vol");
proc print data=perf;
id direction segment;
var accts;
run;
%end;
%else %do;
ods excel options(sheet_name="vol");
proc print data=perf;
id direction segment;
var accts;
run;
%end;
Direction segment accts
A model 17177
A booked 567
A unbooked 5676
B model 17177
B booked 567
B unbooked 5676
如果细分不可用,我将收到以下报告
Direction segment accts
A model 17177
A 1 17177
B model 17177
B 1 17177
Iam计划引入两个宏变量
%let dir =A;
%let Non_segment=y;
基于方向的值,它应该仅给出那些方向,并且如果没有线段(Non_segment = y;),则应该仅具有第一观察值。因此,对于Non_segment = y
,输出如下所示Direction segment accts
A model 17177
答案 0 :(得分:0)
如果没有要测试的变量,则不能仅使用WHERE
语句按组将第一个观测值子集化。您将需要生成一个数据步骤。
data to_print ;
set perf ;
by direction;
%if %length(&dir) %then %do;
where direction="&dir";
%end;
%if %upcase(&non_segment)=Y %then %do;
if first.direction;
%end;
run;
答案 1 :(得分:0)
我尝试了以下代码。
%macro isblank(var);
%if %symexist(&var) %then 1; %*not exist*;
%else %if %sysevalf(%superq(&var)=,boolean) %then 1; %*blank*;
%else 0;
%mend isblank;
%let dir =A;
%let Non_segment=y;
proc print data=new;
%if %isblank(Non_segment) %then (obs=1);*firstobs*;
id direction segment;
var acct;
%else;*all obsevation*;
proc print data =new;
id direction segment;
var acct;
run;
Getting below error
proc print data=new;
78 %if %isblank(Non_segment) %then (obs=1);*firstobs*;
ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.
ERROR: Skipping to next %END statement.
79 id direction segment;
80 var acct;
81 %else;*all obsevation*;
ERROR: The %ELSE statement is not valid in open code.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 6 observations read from the data set WORK.NEW.
NOTE: PROCEDURE PRINT used (Total process time):
real time 10.57 seconds
cpu time 6.31 seconds
82 proc print data =new;
83 id direction segment;
84 var acct;
85 run;