Help using Base SAS procedures

Proc steps

Reply
N/A
Posts: 0

Proc steps

can we do a first. or last. in the proc step itself? if yes, then how?
Super Contributor
Posts: 260

Re: Proc steps

No, you can't. There "variables" are only available during a DATA step, when there is a BY statement.
SAS Super FREQ
Posts: 8,743

Re: Proc steps

Hi:
Olivier is right. First.BYVAR and Last.BYVAR only work for the DATA step. However, PROC REPORT gives you the ability to execute a COMPUTE block BEFORE a group or order variable and/or AFTER a group or order variable and this is the closest you would come to a similar ability in a PROC. So, for example, in PROC REPORT, if you wanted a running total of some variable, for each COUNTRY, then COUNTRY would be your GROUP variable and you might have something like this:
[pre]
compute before country;
runtot = 0;
endcomp;
compute sales;
runtot + sales.sum;
endcomp;
compute after country;
line 'The running total is: ' runtot dollar14. ' for ' country $15.;
endcomp;
[/pre]

In this instance, the compute before country processing might be equivalent to what you do for an IF FIRST.BYVAR condition; and the compute after country processing might be equivalent to what you do for an IF LAST.BYVAR condition. Of course, what you can do here is limited to what you can do with PROC REPORT.

cynthia
Ask a Question
Discussion stats
  • 2 replies
  • 121 views
  • 0 likes
  • 3 in conversation