I have a data set shown here in this screen shot. I need to move through the data set, skip to the even obs, grab the value in Rows, then move back to the previous obs and assign the Rows value I just picked to a column named Count.
So for the first, BpmnObject, move to next Obs (2) and grab Rows - 103 then move back previous Obs (1) and assign rows to Count
So my result set would look like:
| RCT_Object_Type | Count |
| BpmnObject | 3 |
| Miscellaneos | 2 |
| Application | 3216 |
Let's use SASHELP.CARS. Here I'm assigning (incorrectly) the MSRP of the even observations to the odd observation above, outputting only the odd observations, after alteration.
data want;
do i=1 to nob by 2; drop i;
set SASHELP.CARS point=i nobs=nob; /*i is odd*/
j=i+1; drop j;
set SASHELP.CARS (keep=MSRP) point=j ; /*j is even*/
output;
end;
stop;
run;
Let's use SASHELP.CARS. Here I'm assigning (incorrectly) the MSRP of the even observations to the odd observation above, outputting only the odd observations, after alteration.
data want;
do i=1 to nob by 2; drop i;
set SASHELP.CARS point=i nobs=nob; /*i is odd*/
j=i+1; drop j;
set SASHELP.CARS (keep=MSRP) point=j ; /*j is even*/
output;
end;
stop;
run;
Thank you for the quick response! works like a charm! Really appreciate the help.
Much easier to carry values forward then moving them backwards.
data want;
set have ;
if mod(_n_,2)=1 then lagRCT_Object_Type=RCT_Object_Type;
else output;
retain lagRCT_Object_Type;
keep lagRCT_Object_Type Count ;
run;
Thank you Tom for the quick response! I really appreciate the help.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.