BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
devnand
Obsidian | Level 7

I am trying to create a dataset with yearmonth and the decreasing rate.

 

I want to create a dataset with date variable and average rate decaying at a fix rate; After 50 months I want the value to be equal to the

to avg_date as after certain time peroid it will be zero and negative.

 

%let avg_dt=0.02345;
%let avg_date=0.01234;
%let projected_month=50;

 

This give of rate of decrease to be 0.00016

 

For first obs,  date=201708 and rate=0.02345;

for second obs, date=201708 and rate=(0.02345-00016)=0.023289

for third obs, date=201708 and rate=0.023289-00016=0.023128

so that the fifth obs rate=0.01234;

for the date value after that, i want to retain this value.

 

 

 

data dates;
      
         format date yymmn6.;
             date=201601;
         do while(date=202501);
             output;
             date=intnx('month', date, 1);
               rate=lag(&avg_dt)-00016;
          end;
         run;

 

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Have your pick between rate1 and rate2 :

 

%let avg_dt=0.02345;
%let avg_date=0.01234;
%let projected_month=50;
%let startMonth=01AUG2017;

data rates;
do i = 0 to &projected_month;
    month = intnx("MONTH", "&startMonth"d, i);
    rate1 = &avg_dt + (&avg_date-&avg_dt)*i/&projected_month;
    rate2 = &avg_dt * (&avg_date/&avg_dt)**(i/&projected_month);
    output;
    end;
format month yymmn6. rate1 rate2 8.5;
drop i;
run;

proc print; run;
PG

View solution in original post

4 REPLIES 4
Reeza
Super User

The program here depends highly on what you start with.

What does your starting data set look like, or are you creating one from scratch?

devnand
Obsidian | Level 7
Yes, it is from scratch.
Reeza
Super User

You've assumed month is holding its value from line to line. 

 

Treat the rate variable the same. 

 

Dont use lag function, replace it with Rate. This won't answer all your questions but should get you started in right direction. 

PGStats
Opal | Level 21

Have your pick between rate1 and rate2 :

 

%let avg_dt=0.02345;
%let avg_date=0.01234;
%let projected_month=50;
%let startMonth=01AUG2017;

data rates;
do i = 0 to &projected_month;
    month = intnx("MONTH", "&startMonth"d, i);
    rate1 = &avg_dt + (&avg_date-&avg_dt)*i/&projected_month;
    rate2 = &avg_dt * (&avg_date/&avg_dt)**(i/&projected_month);
    output;
    end;
format month yymmn6. rate1 rate2 8.5;
drop i;
run;

proc print; run;
PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 671 views
  • 1 like
  • 3 in conversation