Solved
Contributor
Posts: 34

# 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
Super Contributor
Posts: 359

## 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;``````

All Replies
Super User
Posts: 10,569

## 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
How to convert datasets to data steps
How to post code
Solution
‎12-13-2016 05:52 AM
Super Contributor
Posts: 359

## 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.