Hello SAS users,
Thank you so much in advance for reading the question!
Year 2, Year 3, Year 4, Year 5, year 6, Year 7 ... are New Variables that I want to calculation from the code.
I have the following sample data and code. These are the data steps I needed:
1. From the first firm, Firm 1, randomly select a firm within the SAME group, Firm 2
For example, Firm A in year 2010, whose profit is 100. Randomly match it with firm B in year 1998, whose rate is 0.01.
2. Use Firm 2's Rate * Firm 1's Profit to obtain Firm 1's Year 2.
Year 2 for Firm A in 2010 = 0.01* 100=1
3. Use Firm 1's Year 2, randomly select a firm within the SAME Group, Firm 3
For example, match with Firm C in year 2009, whose Rate is 0.1.
4. Use Firm 3's Rate * Firm 1's Year 2 to obtain Firm 1's Year 3.
Firm A, Year 2010's Year 3 = 0.1*1=0.01
5. Repeat the process for Year 4,5,6,7... for Firm 1, to obtain all Year 4,5,6,7... for Firm 1.
6. Repeat the process for all Year 2,3,4,5,6,7... for all other firms to obtain Year 2,3,4,5,6,7... for all other firms.
Questions:
How do I get all Year 4,5,6,7... for Firm 1?
How do I get Year 2,3,4,5,6,7... for all other firms?
Firm | Year | Rate | Group | Profit | Year 2 | Year 3 | Year 4 | Year 5 | Year 6 | Year 7 |
A | 2010 | 0.1 | 1 | 100 |
|
|
|
|
|
|
A | 2001 | 0.15 | 2 | 97 |
|
|
|
|
|
|
B | 1998 | 0.01 | 1 | 99 |
|
|
|
|
|
|
B | 1995 | 0.2 | 3 | 7 |
|
|
|
|
|
|
B | 1991 | 0.02 | 2 | 109 |
|
|
|
|
|
|
C | 2010 | 0.3 | 2 | 104 |
|
|
|
|
|
|
C | 2020 | 0.05 | 2 | 89 |
|
|
|
|
|
|
C | 2009 | 0.1 | 3 | 3 |
|
|
|
|
|
|
I have the select code, but dont know how to repeat the process.
proc surveyselect data=have sampsize=1 out=mySamples;
strata group;
run;
Data multiply; set mySamples;
Year 2=Profit * Rate;
Run;
Thank you so much in advance!
Maybe i have a hard time understanding the problem, because it is early in the morning and my brain needs caffeine to start working properly, but could you post the numbers you expect as result and the data you have in usable form? It could be much easier to have one year variable with the values 2-7 and another variable containing the value for that year.
Hi @andreas_lds,
The same question with slightly different wording is being discussed here: Random select, do a calculation, then repeat.
@mandyosu01: Please avoid double posting.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.