indentation of SAS code changes when the same program is opened in a Chinese Windows 7

Reply
Contributor
Posts: 61

indentation of SAS code changes when the same program is opened in a Chinese Windows 7

I am a SAS programmer who has low tolerance of code that is not neatly formatted. I make so much effort in indenting my code that it can be read easily. My own computer is English-version 64bits Windows 7 with SAS 9.3. I find out my indentation changes when the progam is opened in another computer that uses Chinese-version 64bits Windows 7 and SAS 9.4. This computer has both SAS 9.3 and SAS 9.4 installed. The indentation change is seen whether the program is opened in SAS 9.3 or SAS 9.4. How can I remedy this? Does it have something to do with encoding?

I am not sure why the image insertion button did not insert a jpg. Please go to the following link to see the indentation change.

http://likecoded.com/indentation-of-sas-code-changes-when-the-same-program-is-opened-in-a-chinese-wi...

Thanks

Super User
Super User
Posts: 7,942

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

Thats because you are using the tab key to indent.  Tab is a special character in the character set, and is interpreted to mean different widths in different applications.  The rule of thumb is to not use tab character, but to set indent levels, say 2 spaces.  SAS editor has a function inbuilt which will put two spaces rather than tab char when tab is pressed, so you get the same functionality, but as they are spaces they are the same width in any application.  To do this, open SAS and click in the Enhanced Editor window.  Now select tools->Options->Enhanced Editor.  Half way down is a section call Tabs.  Select insert spaces for tabs, and set how many (i would suggest 2).

NOte, with regards to your picture of the differences, this is the style setup on the system.  Under the same menu option as the tabs, select appearance, you can set bold/underline etc. as you want.

Respected Advisor
Posts: 4,173

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

I'm with you! I also don't like it if indention gets messed up. One of the first things I'm normally doing when using EG at a new site is to  change the EG default settings. (just tried to insert a screen shot but doesn't work. May be because in the moment this site gets once more "love" from North Korea).

So what I'm normally doing is to change the default settings under "Tools/Options/SAS Programs/Editor Options" to: Tab size; 2, check "Insert spaces for tabs", check "Replace tabs with spaces on file open".

"2" spaces is my preference but anything is o.k. with me as long as all people on the project use the same. I prefer spaces over tabs as this guarantees that code looks the same independent of the editor I'm using.

I would assume that a space uses always a single byte no matter what the encoding is - so not sure why there would be a difference between your environments (unlike with tabs).

If your code gets messed up: Using "ctrl/I" in EG really does "wonder" to code. In the newer versions EG even gets it right with macro code and I've made the code indention EG uses to my "quasi standard". The one thing which imho still would need improvement is SQL indention in EG - but all the rest after a "CTRL/I" is in new EG versions very acceptable for me.

Super User
Posts: 11,343

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

Note that using the "Insert spaces" may also have an appearance issue unless you set the number spaces for indent in the other system to match.

Super User
Super User
Posts: 7,942

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

It shouldn't.  The insert spaces (at least in normal SAS) replaces the tab character with X number of spaces in the actual text file which is saved.  So if I press tab in my file, it puts two spaces - I have to delete twice to get back.  As for the replace tabs with spaces check, that will have an effect on incoming files.  TBH I would avoid tab altogether and just press space bar twice to indent, most modern editors already fill in indentations for you - VBA/ Visual studio etc. pre { and it closes off and indents for example.

Super User
Posts: 11,343

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

What I am referring to is if the other instance of SAS is set up to use 4 as the number of characters to indent then code modified with that editor will have the 4 spaces saved.

I typically use 3 spaces and find code from others with 2, 4 or 5 spaces and my indents don't align with the previous code when I add edits.

Respected Advisor
Posts: 4,173

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

That's what annoys me often. Different people in the same project using different standards for indention. Makes it really hard to end-up  with clean code modified by multiple people. So clearly defined coding standards in a project are a MUST. But yes, reality is: It never works-out 100%. That's why I'm actually really fond of EG's automatic code indention (CTRL/I). I set the options in EG according to the agreed standards and then EG cleans up any code for me before I'm adding my changes. Just what EG does to SQL code still doesn't make me happy - all the rest is quite good.

Super User
Super User
Posts: 7,039

Re: indentation of SAS code changes when the same program is opened in a Chinese Windows 7

The indentation looks fine, but it is not matching the length of the characters.

Looks like you are either using different tab stops or you are using different fonts.

Try changing the FONT used in the Chinese version.


Ask a Question
Discussion stats
  • 7 replies
  • 867 views
  • 2 likes
  • 5 in conversation