BookmarkSubscribeRSS Feed
mandyosu01
Obsidian | Level 7

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!

 

3 REPLIES 3
andreas_lds
Jade | Level 19

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.

FreelanceReinh
Jade | Level 19

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.

mandyosu01
Obsidian | Level 7
Hi,
Thanks for the reply. I edited the message with examples.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1025 views
  • 0 likes
  • 3 in conversation