BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mariapf
Fluorite | Level 6

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_IDPDINDUSTRYMATURITY
130000,45construction3
124000,09retail5
370000,023tech2

 

Desired output

CONTRACT_IDPDINDUSTRYMATURITYYEAR
130000,45construction30
130000,45construction31
130000,45construction32
130000,45construction33
124000,09retail50
124000,09retail51
124000,09retail52
124000,09retail53
124000,09retail54
124000,09retail55
370000,023tech20
370000,023tech21
370000,023tech22
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    do year=0 to maturity;
        output;
    end;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    do year=0 to maturity;
        output;
    end;
run;
--
Paige Miller
mariapf
Fluorite | Level 6
This has worked perfectly, thank you so much for your time!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 788 views
  • 1 like
  • 2 in conversation