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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 608 views
  • 0 likes
  • 2 in conversation