gvkey | fyear | ind | sale | Growth |
1004 | 1980 | 1 | 214 | . |
1032 | 1980 | 1 | 214 | . |
1035 | 1980 | 1 | 214 | . |
1055 | 1981 | 1 | 332 | 1.551402 |
1070 | 1981 | 1 | 332 | 1.551402 |
1086 | 1981 | 1 | 332 | 1.551402 |
1101 | 1981 | 1 | 332 | 1.551402 |
1117 | 1982 | 1 | 445 | 1.340361 |
1132 | 1982 | 1 | 445 | 1.340361 |
1148 | 1982 | 1 | 445 | 1.340361 |
1005 | 1980 | 2 | 325 | . |
1022 | 1980 | 2 | 325 | . |
1027 | 1980 | 2 | 325 | . |
1040 | 1981 | 2 | 356 | 1.095385 |
1051 | 1981 | 2 | 356 | 1.095385 |
1062 | 1981 | 2 | 356 | 1.095385 |
1073 | 1981 | 2 | 332 | 1.095385 |
1084 | 1982 | 2 | 266 | 0.801205 |
1095 | 1982 | 2 | 266 | 0.801205 |
1106 | 1982 | 2 | 266 | 0.801205 |
I want to calculate industry sales growth. The last column is my expected result. sale/lag(sale). But I want it the way I have shown on the table. Can anyone help?
@abdulla I just made up an example, which might capture what you brought up. Does this help?
(Note: I am assuming the input data is sorted by ind, then fyear.)
data have;
input gvkey fyear ind sale;
datalines;
1004 1980 1 214
1032 1980 1 214
1035 1980 1 214
1055 1981 1 332
1070 1981 1 332
1086 1981 1 332
1101 1981 1 332
1117 1982 1 445
1132 1982 1 445
1148 1982 1 445
1234 1980 2 100
2345 1980 2 100
3456 1981 2 115
4567 1981 2 115
5678 1982 2 115
6789 1982 2 115
4321 1983 2 136
5432 1983 2 136
6543 1984 2 175
7654 1984 2 175
;
run;
data want;
set have;
retain growth 0;
by ind fyear;
if first.fyear
then growth = sale / lag(sale);
if first.ind then growth = .;
run;
@abdulla Is this what you're looking for?
data have;
input gvkey fyear ind sale;
datalines;
1004 1980 1 214
1032 1980 1 214
1035 1980 1 214
1055 1981 1 332
1070 1981 1 332
1086 1981 1 332
1101 1981 1 332
1117 1982 1 445
1132 1982 1 445
1148 1982 1 445
;
run;
data want;
set have;
retain growth 0;
by sale;
if first.sale
then growth = sale / lag(sale);
run;
Result:
Yes, that would make sense, although it depends on what you are wanting to calculate: the growth since the last year, or the growth since the last sale amount, and whether it should be broken down by industry, etc. To figure those out, you could use some broader data (or introduce some more of those scenarios input your input dataset).
@abdulla I just made up an example, which might capture what you brought up. Does this help?
(Note: I am assuming the input data is sorted by ind, then fyear.)
data have;
input gvkey fyear ind sale;
datalines;
1004 1980 1 214
1032 1980 1 214
1035 1980 1 214
1055 1981 1 332
1070 1981 1 332
1086 1981 1 332
1101 1981 1 332
1117 1982 1 445
1132 1982 1 445
1148 1982 1 445
1234 1980 2 100
2345 1980 2 100
3456 1981 2 115
4567 1981 2 115
5678 1982 2 115
6789 1982 2 115
4321 1983 2 136
5432 1983 2 136
6543 1984 2 175
7654 1984 2 175
;
run;
data want;
set have;
retain growth 0;
by ind fyear;
if first.fyear
then growth = sale / lag(sale);
if first.ind then growth = .;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.