{"id":5035,"date":"2016-04-02T02:07:42","date_gmt":"2016-04-02T07:07:42","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=5035"},"modified":"2016-04-02T02:14:54","modified_gmt":"2016-04-02T07:14:54","slug":"statistics-guru-predicts-republican-sweep-with-proc-gmap","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/statistics-guru-predicts-republican-sweep-with-proc-gmap\/","title":{"rendered":"Statistics Guru Predicts Republican Sweep! With Proc GMAP"},"content":{"rendered":"<p>Esteemed statistics guru, Dr. Nathaniel Golden has some sobering news for Democrats. His latest models predict a Republican blow out. As can be seen by the map below, the Republican front-runner has tapped into the mood of resentment in the country&#8217;s non-elites. When the dust has settled, only the two highest earning states in the country will remain in the blue column, Maryland and New Jersey (seriously, New Jersey). Code used in creating this map and the statistics behind it can be found below.<\/p>\n<p><a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/04\/mapjoke-results-00001.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-5037\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/04\/mapjoke-results-00001.jpg\" alt=\"Map in all red but 2 states\" width=\"450\" height=\"354\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/04\/mapjoke-results-00001.jpg 1192w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/04\/mapjoke-results-00001-300x236.jpg 300w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2016\/04\/mapjoke-results-00001-1024x806.jpg 1024w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>Step 1: Create a data set<\/p>\n<p>Oh, and\u00a0<em>April Fool&#8217;s ! \u00a0<\/em>I just made up these data. If you really do need a data set with state data aligned to SAS maps, though, you can do what I did and<a href=\"http:\/\/www.ats.ucla.edu\/stat\/sas\/code\/gmap.htm\"> pull it from the UCLA Stats Site<\/a>. If you had real data, say percent of people who use methamphetamine, or whatever, you could just replace the last column there with your data. Since I did not have actual data, I just created a variable that was 40,000 for everything less than 51,000, and 51,000 for everything over. I&#8217;m going to use that in the PROC FORMAT below.<\/p>\n<p>Also, even though my data are not nicely aligned here, note that the statename variable has a width of 20 so make sure you align your data like that so that state comes in column 22 or after.<br \/>\n<code><br \/>\nDATA\u00a0income2000;<br \/>\nINPUT\u00a0statename $20. state income ;<br \/>\nIF\u00a0income &lt; 51000 THEN vote = 40000 ;<br \/>\nELSE\u00a0vote = 51000 ;<br \/>\nDATALINES ;<br \/>\nMaryland 24 51695<br \/>\nAlaska 2 50746<br \/>\nNew Jersey 34 51032<br \/>\nConnecticut 9 50360<\/code><\/p>\n<p>&#8212; a bunch more data<\/p>\n<p>;<\/p>\n<p>Here&#8217;s how you set up a PROC FORMAT for the two categories.<br \/>\n<code><br \/>\nPROC FORMAT<br \/>\nVALUE\u00a0votfmt low-50000=\"Republican\"<br \/>\n50001-high=\"Democrat\";<\/code><\/p>\n<p>*** Making the patterns red and blue ;<br \/>\n<code><br \/>\npattern1 value=msolid color=red;<br \/>\npattern2 value=msolid color=blue;<\/code><\/p>\n<p>*** Making the map ;<\/p>\n<p><code>proc gmap data = income2000 map=maps.us;<br \/>\nid state;<br \/>\nchoro vote;<br \/>\nformat vote votfmt.;<\/code><\/p>\n<p>The important thing to keep in mind is if you want a U.S. map with the states that maps.us is in a SAS library named maps. Like the sashelp library, it&#8217;s already there, you don&#8217;t need to create it or assign it in the LIBNAME statement, you can just reference it. Go look under your libraries. See, I was right.<\/p>\n<p>And don&#8217;t forget to vote. \u00a0I don&#8217;t care how busy you are. You don&#8217;t want this, do you?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esteemed statistics guru, Dr. Nathaniel Golden has some sobering news for Democrats. His latest models predict a Republican blow out. As can be seen by the map below, the Republican front-runner has tapped into the mood of resentment in the country&#8217;s non-elites. When the dust has settled, only the two highest earning states in the&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,11],"tags":[],"class_list":["post-5035","post","type-post","status-publish","format-standard","hentry","category-software","category-statistics"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5035","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=5035"}],"version-history":[{"count":5,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5035\/revisions"}],"predecessor-version":[{"id":5042,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/5035\/revisions\/5042"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=5035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=5035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=5035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}