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

Hi,

I want to create a new variable that increases by 1 every third observation.  I'm pasting the simple formula from excel below.  Is there a way to replicate this in SAS, so that it will create several million rows in this fashion?

Thank you

Capture.JPGCapture2.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@Hess Hi and welcome to the SAS Community 🙂

 

Are you looking for something like this?

 

data want;
   do _N_=1 to 10;
      if mod(_N_, 3)=1 then a+1;
      output;
   end;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data want;
    set have;
    newvariable = ceil(_n_/3);
run;

The CEIL() function rounds the value inside the parenthesis up to the next integer, so rows 1 2 and 3 will round up to a 1; and so on.

 

Advice ... stop thinking about how to do it in Excel, as this likely will not help in SAS. I know this is difficult to do if you are a beginner in SAS, but the advice will help you in the long run.

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

@Hess Hi and welcome to the SAS Community 🙂

 

Are you looking for something like this?

 

data want;
   do _N_=1 to 10;
      if mod(_N_, 3)=1 then a+1;
      output;
   end;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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