BookmarkSubscribeRSS Feed
deleted_user
Not applicable
can we do a first. or last. in the proc step itself? if yes, then how?
2 REPLIES 2
Olivier
Pyrite | Level 9
No, you can't. There "variables" are only available during a DATA step, when there is a BY statement.
Cynthia_sas
Diamond | Level 26
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1072 views
  • 0 likes
  • 3 in conversation