BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JeffreyLowe
Obsidian | Level 7

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_TypeCount
BpmnObject3
Miscellaneos2
Application3216

 

JeffreyLowe_0-1609260362094.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PhilC
Rhodochrosite | Level 12

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;

 

View solution in original post

4 REPLIES 4
PhilC
Rhodochrosite | Level 12

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;

 

JeffreyLowe
Obsidian | Level 7

Thank you for the quick response! works like a charm! Really appreciate the help.

Tom
Super User Tom
Super User

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;
JeffreyLowe
Obsidian | Level 7

Thank you Tom for the quick response! I really appreciate the help.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 6866 views
  • 2 likes
  • 3 in conversation