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!
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.