Hi all! I have a dataset with county voting records for presidential elections. For example,
County State Democrat_1992 Republican_1992 Democrat_1996 Republican_1996
Autauga AL 4819 8715 5015 9519
Baldwin AL 12195 26270 12776 29476
I want to transform this data so I can work with it more easily by having years as a column. I actually will need to linearly interpolate the data between the years, so ideally I need:
County State Year Democrat Republican
Autauga AL 1992 4819 8715
Autauga AL 1993 . .
Autauga AL 1994 . .
Autauga AL 1995 . .
Autauga AL 1996 5015 9519
Baldwin AL 1992 12195 26270
Baldwin AL 1993 . .
Baldwin AL 1994 . .
Baldwin AL 1995 . .
Baldwin AL 1996 12776 29476
So that I can then linearly interpolate for the years with missing data. I would really appreciate any help with this!! Thank you!
Something like that below I reckon. You have two "problems" as your data stands
step1
proc transpose by county/state
step2 data step
year=input(substr(_NAME_, -1, 4) best32,)); /* to convert Democrat_1992 into numeric year 1992 */
step 3 - retranspose to get democrat and republican columns
step 4 data step iteration to create the missing years if they're really needed for your interpolation calculation.
Vince
Something like that below I reckon. You have two "problems" as your data stands
That worked perfectly! Thank you so, so much!
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.