Hi forum,
I have a dataset with >400 cities. Each city has population-values for all quarters of 2 years (Q1 2019, Q2 2019, ..., Q4 2020). I want to create a new variable (pop_q4_2020) with the values of Q4 2020 of the respecitve city. Thats what I have:
data have;
input city $ year quarter population;
datalines;
CityA 2019 3 20029
CityB 2019 2 34900
CityA 2020 2 19853
CityB 2020 2 34500
CityA 2019 2 20029
CityA 2020 4 19853
CityB 2020 4 34300
CityA 2019 4 20029
CityB 2019 3 34800
CityB 2020 1 34600 CityA 2019 1 20135 CityA 2020 3 19853
CityB 2020 3 34400
CityB 2019 4 34700
CityA 2020 1 20029
CityB 2019 1 35000
;
run;
Thats what I want:
Region
year
quarter
pop_q4_2020
CityA
2019
3
19853
CityB
2019
2
34300
CityA
2020
2
19853
CityB
2020
2
34300
CityA
2019
2
19853
CityA
2020
4
19853
CityB
2020
4
34300
CityA
2019
4
19853
CityB
2019
3
34300
CityB
2020
1
34300
CityA
2019
1
19853
CityA
2020
3
19853
CityB
2020
3
34300
CityB
2019
4
34300
CityA
2020
1
19853
CityB
2019
1
34300
I tried it with this steps: create a new var and copy the value of population-var if year=2020 and quarter=4. But I dont know how to copy the values into the cells with the same city-names.
Thank you for help!
... View more