2 weeks ago
I am new to SAS. I used to use Excel for some statistical analysis, but I am in trouble with larger size data now. I am a new SAS learner. If I cannot make the question clear, or not using right SAS terms, please be nice I tried to create a sample data, but I ran into format issues. So, i will use the following as example.
I have a data like: ( city names: a, b, c; province names: x, y, z)
individual city2010 province2010 city2011 province2011 city2012 province2012 ........
1 a x b x c y
2 a x c y d z
3 c y a x a x
4 .......................................................................(more data)
So, it reads like: individual 1 lives in city "a" which is in province "x" in 2010. Then she/he moves to city "b" (also in province "x") in 2011, etc...
I also have a yearly province-level data with information of average income for each province and each year.
province "x" average income in 2011 is 90
province "y" average income in 2011 is 100
province "z" average income in 2011 is 80
The above numbers will be used for below example.
My study is about to see the relationship between the number of individuals move from PROVINCE to PROVINCE and income ratios, i.e. not city level. I would like to prepare a data like:
year province_from province_to count income_ratio
2011 x y 1 (province_to_income2011)/(province_from_ income2011) = 100/90
2011 x z 0 (province_to_income2011)/(province_from_ income2011) = 80/90
2011 y x 1 (province_to_income2011)/(province_from_ income2011) = 90/100
2011 y z 0 (province_to_income2011)/(province_from_ income2011) = 80/100
2012 x y 1 (province_to_income2011)/(province_from_ income2011) = 100/90
2012 x z ..............
So, this will be province-level for each year for each pair of provinces data.
I know this is a long story. I hope it is clear. Otherwise, please ask any questions. And, any help is great for me!
Thanks in advance.
2 weeks ago - last edited 2 weeks ago
You could make your work a lot easier by changing your data format to
individual year city province
with one row per individual and year.
Your other dataset would be
province year income
Then you could get your summary statistics by combining the two datasets like this:
proc sql; create table moves as select A.year as fromYear, B.year as toYear, A.province as fromProvince, B.province as toProvince, count(*) as n from resid as A inner join resid as B on A.year+1 = B.year and A.province ne B.province group by A.year, B.year, A.province, B.province; create table moveRatios as select A.*, C.income / B.income as incomeRatio from moves as A inner join income as B on A.fromProvince = B.province and A.fromYear = B.year inner join income as C on A.toProvince = C.province and A.toYear = C.year; quit;