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
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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