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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 612 views
  • 0 likes
  • 3 in conversation