- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DATA &Portfolio_VAL2(Keep=MOB_VAL_P MOB ); set &Portofo._VAL; by MOB; if first.MOB then CNT=0; CNT+1; MOB_VAL_P=cnt/&total_val,; if last.MOB; run;
hi can you let me know what does the statement "by MOB;" doing on the third row? what does it mean when it comes after set statement? also should the "if last.MOB" statement put higher up? or it does not matter where it is positioned?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It initiates BY group processing, a prt of it is creation the autmatic.first and .last variables.
It's a whole concept, you could read about in the documentqation.
I think you need to keep .last where it is, since it stops processing of subsequent statements for that record (if it doesn't meet the criteria).
The easiest way to find out how things work, try to run the code yourself, examine the results, and if needed use the data step debugger.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if last.mob;
probably belongs where it is.
You can easily see what effect it has, by deleting it, or moving it, and looking at the data set, and see what happens. As stated by @LinusH you should really read the documentation on these extremely important FIRST. and LAST. variables.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can move the subsetting IF up one line, to avoid calculating MOB_VAL_P in ever data step iteration, when it is really needed only once. I also streamlined the first condition, so that the unnecessary increment in the first observation of a group is avoided.
data &Portfolio_VAL2 (keep=MOB_VAL_P MOB );
set &Portofo._VAL;
by MOB;
if first.MOB
then CNT = 1;
else CNT + 1;
if last.MOB;
MOB_VAL_P = cnt / &total_val.;
run;