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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.