{"id":2463,"date":"2012-06-09T01:14:32","date_gmt":"2012-06-09T06:14:32","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=2463"},"modified":"2012-06-09T01:34:47","modified_gmt":"2012-06-09T06:34:47","slug":"javascript-is-not-sas","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/javascript-is-not-sas\/","title":{"rendered":"Javascript is not SAS"},"content":{"rendered":"<p>I decided I need to learn a new language. I had learned a number of languages in the past but SAS is the only one I used on a daily basis. I write SPSS syntax about every other day (does that count?). I toyed with Ruby and C++. \u00a0I listened, bemusedly, to people who exhorted me to learn R. In the end, I settled on Javascript and we are having a good relationship.<\/p>\n<p>My choice was based on needing something that was better at stuff SAS isn&#8217;t very good at. I needed something that would create dynamic web pages, was easy for user interaction. Also, I think it is good to get out of your comfort zone from time to time. Now js and I are on an initials basis. There are a few ways that I still frequently get thrown off, though.<\/p>\n<p><strong>Arrays subscripts.<\/strong><\/p>\n<p>In SAS, to refer to the ith value in an array named bob, I use bob{i}<\/p>\n<p>In javascript, you&#8217;d use \u00a0bob[i]<\/p>\n<p>I have had to delete the curly brackets and replace them with square ones approximately 40 zillion times<\/p>\n<p>Also, arrays begin with 0 in javascript and 1 with SAS. So, every index value is one less in js. The third element of bob is bob[2]<\/p>\n<p>For some reason, that was far easier for me to adapt to than the bracket difference. A reasonable person might say this is wrong and argue that counting starts at one.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-thumbnail wp-image-2464\" title=\"house\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/06\/MC900439770-150x150.png\" alt=\"house with candy on roof\" width=\"150\" height=\"150\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/06\/MC900439770-150x150.png 150w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/06\/MC900439770.png 288w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/p>\n<p>I went back to apples. If you are counting apples, you start at 1. If you are measuring distance, you start at zero. When you start to go somewhere you are not 1 mile or 1 foot or one anything from your house. You are at point zero.<\/p>\n<p>Javascript = house<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-2465\" title=\"Apple\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/06\/MP900438641-150x150.jpg\" alt=\"red apple\" width=\"150\" height=\"150\" \/><\/p>\n<p>SAS = apple<\/p>\n<p>&nbsp;<\/p>\n<p><strong>DO loops &#8211; in a good way<\/strong><\/p>\n<p>Another way javascript is different is do loops.<\/p>\n<p>Take this \u00a0example of how you would do a loop in SAS:<\/p>\n<p>DO i = 1 to DIM(bob) ;<\/p>\n<p>some programming stuff ;<\/p>\n<p>END ;<\/p>\n<p>Then, at the end of your program, you need to delete i or it sticks around forever. In javascript, you do this;<\/p>\n<p>for (i=0; i &lt; facts.length ; i++) {<\/p>\n<p>some programming stuff<\/p>\n<p>}<\/p>\n<p>Because you set the counter to 0 at the beginning, you can re-use the same counter variable over and over in your program. Of course, you could re-do this in SAS by re-setting i to 1 after every DO loop but that takes an extra statement. I usually just use different variable names &#8211; i,j, k &#8211; and drop them all in the DROP statement at the end of my program.<\/p>\n<p>The moral of the day is, if you are a SAS programmer and are interested in picking up a new language, there are certainly worse choices than javascript. Much of what you are comfortable with from SAS will transfer. However, there are the odd differences, some of which, like the different type of brackets for arrays, which will make your life difficult and others, like the for style for DO loops that can make your life easier.<\/p>\n<p>I have more to say about SAS and javascript and why I chose javascript but for now, I need to write a post on why Codecademy is not the way to learn to code.<\/p>\n<p>&nbsp;<\/p>\n<p><em>**** Thank you to <a href=\"https:\/\/twitter.com\/#!\/stat_geek\">@stat_geek on twitter<\/a> who tweeted that you could also use [] in SAS and they would work. My point is that I have always used {} and have never used the square brackets and old habits are hard to break. Tomorrow I am going to have to change some of my SAS programs to use [] just so I can be one of the cool kids.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided I need to learn a new language. I had learned a number of languages in the past but SAS is the only one I used on a daily basis. I write SPSS syntax about every other day (does that count?). I toyed with Ruby and C++. \u00a0I listened, bemusedly, to people who exhorted&#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],"tags":[],"class_list":["post-2463","post","type-post","status-publish","format-standard","hentry","category-software"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/2463","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=2463"}],"version-history":[{"count":4,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/2463\/revisions"}],"predecessor-version":[{"id":2467,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/2463\/revisions\/2467"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=2463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=2463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=2463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}