BookmarkSubscribeRSS Feed
saseles
Calcite | Level 5

Hello Everyone,

 

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 Man Happy 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.

 

e.g.

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.

 

 

    

 

1 REPLY 1
PGStats
Opal | Level 21

You could make your work a lot easier by changing your data format to

 

Data resid:

individual year city province

 

with one row per individual and year.

 

Your other dataset would be

 

Data income:

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;

(untested)

 

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 501 views
  • 2 likes
  • 2 in conversation