DATA Step, Macro, Functions and more

How to trend the last two months (difference in percent)

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

How to trend the last two months (difference in percent)

[ Edited ]

If we have past all month file and , new file with current month then how we calculate the that current month from one file and last month from all month file
Percent difference


Accepted Solutions
Solution
‎12-13-2016 05:52 AM
Regular Contributor
Posts: 194

Re: How to trend the last two months (difference in percent)

Hi,

 

data old new;
    infile datalines dlm=",";
    format month x 2.;
    input month x;
    if month=4 then output new;
    else output old;
    datalines;
1,10,
2,5,
3,12,
4,15
;
run;

data want;
    set old new end=a;
    y=lag(x);

    if a then do;
        diff=100*(x-y)/y;
        output;
    end;

	drop y;
run;

View solution in original post


All Replies
Super User
Posts: 6,946

Re: How to trend the last two months (difference in percent)

Please supply example data in a data step so we have something to play with.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎12-13-2016 05:52 AM
Regular Contributor
Posts: 194

Re: How to trend the last two months (difference in percent)

Hi,

 

data old new;
    infile datalines dlm=",";
    format month x 2.;
    input month x;
    if month=4 then output new;
    else output old;
    datalines;
1,10,
2,5,
3,12,
4,15
;
run;

data want;
    set old new end=a;
    y=lag(x);

    if a then do;
        diff=100*(x-y)/y;
        output;
    end;

	drop y;
run;
Contributor
Posts: 34

Re: How to trend the last two months (difference in percent)

Grand salute gamotte.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 131 views
  • 1 like
  • 3 in conversation