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
@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;
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.
@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;
thank you!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.