Help using Base SAS procedures

Generate incremental data based on a pattern

Reply
Occasional Contributor
Posts: 15

Generate incremental data based on a pattern

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
N/A
Posts: 0

Re: Generate incremental data based on a pattern

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
Occasional Contributor
Posts: 15

Re: Generate incremental data based on a pattern

Posted in reply to deleted_user
It worked.
Thank you Sukanya.
Ask a Question
Discussion stats
  • 2 replies
  • 99 views
  • 0 likes
  • 2 in conversation