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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.