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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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