BookmarkSubscribeRSS Feed
osho
Calcite | Level 5
I'm trying to generate incremental data in a dataset based on a pattern.
For example I have a dataset with only 1 field and 1 record with value =2 and I want it to increment by 2 without replacing the old one.


Initial dataset:
-------------
count
2

My goal:
----------
2
4
6
8
10

The problem I am having is , when I write the code to generate the pattern, the new value (incremented ) replaces the old value so I only get 1 record.

Here's my code


data test;
num=1;
run;

data test1;
set test;
by num;
retain count 0;
if first.num then do;
count=count+2;
end;
run;


Once I get the code right, I will be replicating it to generate datetime fields from May 20 1980 to June 6 2008, with dates at 6 hours intervals captured one below the other in the dataset.

Thanks in advance. Message was edited by: osho
2 REPLIES 2
deleted_user
Not applicable
Inlcude do loop and Output statment. Where i is how many times you want to increment the value. See the bleow code. Let me know if it deosn't solve your purpose.

data test;
num=1;
run;

data test1;
set test;
by num;
retain count 0;
if first.num then count=0;
do i=1 to 5;
count=count+2;
output;
end;
run;

~ Sukanya E
osho
Calcite | Level 5
It worked.
Thank you Sukanya.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1197 views
  • 0 likes
  • 2 in conversation