Hi all,
I have a problem creating a variable that I think can be solved using some sort of loop but I don't know how to code it. I have an input dataset with information about mortgages, including the maturity for each one. I need to create a variable called year, that creates a line for each year from 0 to maturity for each contract. Therefore, the output dataset will have as many lines as contracts times (maturity +1, accounting for the zeroes). Below I set an example of my input and my expected output, so that it is easier to understand:
Input
| CONTRACT_ID | PD | INDUSTRY | MATURITY |
| 13000 | 0,45 | construction | 3 |
| 12400 | 0,09 | retail | 5 |
| 37000 | 0,023 | tech | 2 |
Desired output
| CONTRACT_ID | PD | INDUSTRY | MATURITY | YEAR |
| 13000 | 0,45 | construction | 3 | 0 |
| 13000 | 0,45 | construction | 3 | 1 |
| 13000 | 0,45 | construction | 3 | 2 |
| 13000 | 0,45 | construction | 3 | 3 |
| 12400 | 0,09 | retail | 5 | 0 |
| 12400 | 0,09 | retail | 5 | 1 |
| 12400 | 0,09 | retail | 5 | 2 |
| 12400 | 0,09 | retail | 5 | 3 |
| 12400 | 0,09 | retail | 5 | 4 |
| 12400 | 0,09 | retail | 5 | 5 |
| 37000 | 0,023 | tech | 2 | 0 |
| 37000 | 0,023 | tech | 2 | 1 |
| 37000 | 0,023 | tech | 2 | 2 |
data want;
set have;
do year=0 to maturity;
output;
end;
run;
data want;
set have;
do year=0 to maturity;
output;
end;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.