[patch] SAS syntax and indent scripts

171 views
Skip to first unread message

Zhen-Huan Hu

unread,
Mar 10, 2017, 3:59:39 PM3/10/17
to vim_dev
Vim is shipped with a default SAS syntax script but it has not been updated for some time and many new statements and keywords introduced in the later version of SAS are not supported. Vim does not have an indent script for SAS.

Attached are the SAS syntax and indent scripts that I have been maintaining on vim.org for quite a few years. The syntax script is much more accurate and supports more features in the SAS language. They are also patched and updated to the latest version of SAS (as of Mar 2017).

I also attached an example SAS file here in case you want to see the differences.

sas.vim
sas.vim
lifetest.sas

Bram Moolenaar

unread,
Mar 11, 2017, 1:22:14 PM3/11/17
to vim...@googlegroups.com, Zhen-Huan Hu
Thanks. The indent file is new, I can include that.

There already is a SAS syntax file. Did you contact the maintainer,
James Kidd?


--
From "know your smileys":
:-| :-| Deja' vu!

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Zhen-Huan Hu

unread,
Mar 11, 2017, 3:17:13 PM3/11/17
to vim_dev, nove...@gmail.com
On Saturday, March 11, 2017 at 12:22:14 PM UTC-6, Bram Moolenaar wrote:
> Thanks. The indent file is new, I can include that.
>
> There already is a SAS syntax file. Did you contact the maintainer,
> James Kidd?

No, I haven't. I am not very familiar with the process but if it is a completely different script, do I still need to contact the original maintainer?

Bram Moolenaar

unread,
Mar 12, 2017, 11:33:07 AM3/12/17
to vim...@googlegroups.com, Zhen-Huan Hu
I don't know the language, thus I can't judge wheter we are missing
something from the existing file. Also, some people might be upset if
we drop their file from the distribution without even asking. But maybe
they are glad to see a better replacement, better ask.

--
hundred-and-one symptoms of being an internet addict:
94. Now admit it... How many of you have made "modem noises" into
the phone just to see if it was possible? :-)

Zhen-Huan Hu

unread,
Mar 13, 2017, 11:46:17 AM3/13/17
to vim_dev, nove...@gmail.com
On Sunday, March 12, 2017 at 10:33:07 AM UTC-5, Bram Moolenaar wrote:
> I don't know the language, thus I can't judge wheter we are missing
> something from the existing file. Also, some people might be upset if
> we drop their file from the distribution without even asking. But maybe
> they are glad to see a better replacement, better ask.

That makes sense. I will try to contact the original maintainer.

Zhen-Huan Hu

unread,
Mar 13, 2017, 11:52:31 AM3/13/17
to vim_dev, nove...@gmail.com
I also found an issue in the indent script. Please use the latest one here:
http://www.vim.org/scripts/download_script.php?src_id=25030

(Somehow, when I try to attach the file directly, I keep getting the error from Google groups...)

Bram Moolenaar

unread,
Mar 13, 2017, 5:30:03 PM3/13/17
to vim...@googlegroups.com, Zhen-Huan Hu
I'll include the update. You can use a normal mail client to send
messages to the group. Attaching should work then.

--
hundred-and-one symptoms of being an internet addict:
113. You are asked about a bus schedule, you wonder if it is 16 or 32 bits.

Keny Hu

unread,
Mar 23, 2017, 11:34:33 AM3/23/17
to Bram Moolenaar, vim...@googlegroups.com
Hi Bram,

I have talked to James Kidd who maintains the SAS syntax script. He kindly agreed to have me assume the maintenance task for him. Please let me know if this is okay with you.

Best,

Zhen-Huan
sas.vim

Bram Moolenaar

unread,
Mar 23, 2017, 5:17:26 PM3/23/17
to Keny Hu, Kidd, James P., vim...@googlegroups.com

Keny Hu wrote:

> I have talked to James Kidd who maintains the SAS syntax script. He kindly
> agreed to have me assume the maintenance task for him. Please let me know
> if this is okay with you.

Very good, thanks for taking over.


--
% cat /usr/include/sys/errno.h
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
[...]
#define EMACS 666 /* Too many macros */
%

Blay263

unread,
Aug 25, 2017, 7:50:09 PM8/25/17
to vim_dev, nove...@gmail.com, James...@covance.com

The indent file is not working on my windows machine.and the syntax file doesn't highlight anything after a datelines statement.

I tried the files https://github.com/EricGebhart/SAS-Vim/blob/master/indent/sas.vim here they work but have limitations.

Zhen-Huan Hu

unread,
Aug 26, 2017, 12:58:12 AM8/26/17
to vim_dev, nove...@gmail.com, James...@covance.com
On Friday, August 25, 2017 at 6:50:09 PM UTC-5, Blay263 wrote:
> The indent file is not working on my windows machine.and the syntax file doesn't highlight anything after a datelines statement.
>
> I tried the files https://github.com/EricGebhart/SAS-Vim/blob/master/indent/sas.vim here they work but have limitations.

Are your SAS files recognized correctly by Vim? What is the "filetype" value?

Does this happen to all SAS files or just some specific files? Could you send me a sample file with indent/syntax issue to see if I can reproduce the issue?

As for the dataline syntax, do you have a semicolon at the start of a newline to mark the end of a dataline block? A dataline block in SAS needs to be written as:

dataline
xx xx xx
xx xx xx
;

The semicolon must be the first character in a new line to form a null statement; otherwise SAS will throw an error.

Message has been deleted

Blay263

unread,
Aug 26, 2017, 2:00:41 AM8/26/17
to vim_dev, nove...@gmail.com, James...@covance.com

I have added the before and after issuing the command gg=G in normal mode.As you can see there is no indenting at all.

I have also added a file with no syntax highlighting.It works in sas 9.4

before indent.png
After indent.png
no syntax.png

Keny Hu

unread,
Aug 26, 2017, 2:06:42 AM8/26/17
to Blay263, vim_dev
Please try the attached syntax file and let me know if it solves the syntax issue.

On Sat, Aug 26, 2017 at 12:59 AM, Blay263 <tate...@gmail.com> wrote:
On Saturday, August 26, 2017 at 12:58:12 AM UTC-4, Zhen-Huan Hu wrote:
sas.vim

Blay263

unread,
Aug 26, 2017, 2:30:42 AM8/26/17
to vim_dev, tate...@gmail.com

Perfect Thanks,syntax works

Bram Moolenaar

unread,
Aug 26, 2017, 11:49:33 AM8/26/17
to vim...@googlegroups.com, Keny Hu, Blay263

Keny Hu wrote:

> Please try the attached syntax file and let me know if it solves the syntax
> issue.

I suppose it's OK to include this fixed version.

--
Far out in the uncharted backwaters of the unfashionable end of the
Western Spiral arm of the Galaxy lies a small unregarded yellow sun.
Orbiting this at a distance of roughly ninety-eight million miles is an
utterly insignificant little blue-green planet whose ape-descended life
forms are so amazingly primitive that they still think digital watches
are a pretty neat idea ...
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

Keny Hu

unread,
Aug 26, 2017, 2:43:59 PM8/26/17
to Bram Moolenaar, vim_dev, Blay263
I suppose so. It's just a minor change of the regex to capture the end of a dataline block from '^;' to '^\s*;'

Blay263

unread,
Aug 27, 2017, 10:03:49 AM8/27/17
to vim_dev
Any update on the indenting issue

Keny Hu

unread,
Aug 27, 2017, 7:55:50 PM8/27/17
to vim_dev
I don't know what's causing the issue. Does it happen to all SAS files? Could you replicate the issue without any third-party plugins?
 

On Sun, Aug 27, 2017 at 9:03 AM, Blay263 <tate...@gmail.com> wrote:
Any update on the indenting issue

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/CflWb5jChQ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Glessner

unread,
Jun 21, 2018, 10:43:29 AM6/21/18
to vim_dev
On Sunday, August 27, 2017 at 7:55:50 PM UTC-4, Zhen-Huan Hu wrote:
> I don't know what's causing the issue. Does it happen to all SAS files? Could you replicate the issue without any third-party plugins?
>  
>
>
> On Sun, Aug 27, 2017 at 9:03 AM, Blay263 <tate...@gmail.com> wrote:
> Any update on the indenting issue
>
>
>
>
>
> --
>
> --
>
> You received this message from the "vim_dev" maillist.
>
> Do not top-post! Type your reply below the text you are replying to.
>
> For more information, visit http://www.vim.org/maillist.php
>
>
>
> ---
>
> You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
>
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/CflWb5jChQ4/unsubscribe.
>
> To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Sorry to be posting to this a year later, but I just found this thread. I'm facing the same issue with the indent plugin not working properly. Specifically, it seems no text automatically indents and normal gg=G removes all indentation, as Blay263 pointed out.

I am running 32-Bit gVim 8.1 on Windows. For me, this affects all SAS files. I was able to confirm I get the same behavior running no plugins in both Vim and gVim (vim -u NONE). I checked that the plugin was indeed loaded (echo exists("*GetSASIndent")), but it will not indent.

Keny Hu

unread,
Jun 21, 2018, 11:49:18 AM6/21/18
to vim_dev
Is the SAS file type correctly recognized? What's the output of ":filetype" command in your SAS file? If it shows "filetype detection:off" you would need to have somthing like this: https://github.com/akanosora/vimfiles/blob/master/ftdetect/sas.vim under your /vimfiles/ftdetect folder (I don't think Vim automatically recognizes SAS files). Otherwise, you can try to switch auto indent on by typing ":filetype indent on".

To unsubscribe from this group and all its topics, send an email to vim_dev+unsubscribe@googlegroups.com.

Chris Glessner

unread,
Jun 21, 2018, 1:16:03 PM6/21/18
to vim_dev
I use autocommands in my usual setup to detect SAS files and set them up accordingly. So ":set filetype" returns "filetype=sas" and ":filetype" returns "filetype detection:ON plugin:ON indent:ON" when I'm editing a .sas file. I also set autoindent in my vimrc. Not sure what the expected configuration is for that, but my setup was working well on Vim 8.0 and only broke yesterday, when I installed Vim 8.1.

Regarding running with no plugins, I did manually specify ":set filetype=sas" and ":filetype plugin indent on" and confirmed they were set before trying out some code. It still would not indent.

Blay263

unread,
Jun 24, 2018, 2:27:16 PM6/24/18
to vim_dev
This file works sometimes .https://github.com/EricGebhart/SAS-Vim/blob/master/indent/sas.vim. There is clearly something wrong with the "new" indent file.

Christian Brabandt

unread,
Jun 24, 2018, 3:58:44 PM6/24/18
to vim_dev

On So, 24 Jun 2018, Blay263 wrote:

> This file works sometimes .https://github.com/EricGebhart/SAS-Vim/blob/master/indent/sas.vim. There is clearly something wrong with the "new" indent file.

Please provide clear steps how to reproduce the issue.

Best,
Christian
--
F: Was haben seit der Rechtschreibreform Jesus Christus und ein Opel
Vectra gemeinsam?
A: Es sind beides Märtyrer.

Blay263

unread,
Jun 24, 2018, 5:42:04 PM6/24/18
to vim_dev
As i mentioned above issuing the command gg=G in a sas file removes all indention and the text is left aligned.

Christian Brabandt

unread,
Jun 24, 2018, 5:45:43 PM6/24/18
to vim_dev

On So, 24 Jun 2018, Blay263 wrote:

> As i mentioned above issuing the command gg=G in a sas file removes all indention and the text is left aligned.

With what file? Did you start with vim --clean?


Best,
Christian
--
Letzte Worte eines Grillmeisters:
"Hein, gib mal den Spiritus rüber."

Blay263

unread,
Jun 25, 2018, 3:59:06 PM6/25/18
to vim_dev
So just to give more context about a year ago the SAS vim files were updated. For the most part the updates were great but indenting hasn't worked since then.To reproduce: gvim --clean test.sas(attached). Then =G.indentation is removed . Expect indentation .
Capture2.PNG
Capture.PNG
test.sas

Keny Hu

unread,
Jun 25, 2018, 8:27:57 PM6/25/18
to vim_dev
I uploaded the syntax file but not the indent file. Couldn't remember who submitted the indent file. Could you try if this indent file work for you: https://github.com/akanosora/vimfiles/tree/master/indent

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/CflWb5jChQ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+unsubscribe@googlegroups.com.

Christian Brabandt

unread,
Jun 26, 2018, 2:06:47 AM6/26/18
to Blay263, Keny Hu, vim_dev

On Mo, 25 Jun 2018, Blay263 wrote:
> So just to give more context about a year ago the SAS vim files were
> updated. For the most part the updates were great but indenting hasn't
> worked since then.To reproduce: gvim --clean test.sas(attached). Then
> =G.indentation is removed . Expect indentation .

First of all, I don't know the language, but I found two problems with
the distributed indent script. It worked for me in my regular setup, but
didn't work when using vim --clean for two reasons:

1) It seems, statements are case insensitive. However the indent
script does not account for that and uses whatever your
'ignorecase' setting is. That should be fixed by using the `=~#`
for matching regexpes.
2) The indent script uses the softtabstop value directly. But that
might be zero or negative, in which case I think the
shiftwidth() function should be used.

With those changes, it indents your file to:

,----
| Proc sql;
| create table legacy as
| select * from table1 as a
| where a.PolNo in (select distinct PolNo from table2);
| quit;
`----

Attached is the patch for Keny to apply.

Best,
Christian
--
Jeder sollte sich eine Überseh-Stunde seines Tags oder Treibens
wählen, und zwar nicht eine spazierende im Freien, sondern eine dunkle
in der Dämmerung, wo nichts ihn durch seine Sinnen unterbricht.
-- Jean Paul
sas_indent.patch

Keny Hu

unread,
Jun 26, 2018, 11:39:35 AM6/26/18
to Blay263, Keny Hu, vim_dev
Thank you for the patch. Christian. Here is the updated indent file for SAS.
sas.vim

Christian Brabandt

unread,
Jun 26, 2018, 2:05:52 PM6/26/18
to vim_dev

On Di, 26 Jun 2018, Keny Hu wrote:

> Thank you for the patch. Christian. Here is the updated indent file for SAS.

Actually, I am not sure if the test for the softtabstop setting is
actually needed of if not rather instead you should always use
shiftwidth() Since that is what it is for, indent by amount number of
shiftwidth. And I think that is what most other indent scripts use.

Best,
Christian
--
Das Alter hört sich gern, auch wenn es nichts zu sagen hat.
-- Johann Wolfgang von Goethe

Keny Hu

unread,
Jun 26, 2018, 3:06:55 PM6/26/18
to vim_dev
That makes sense. Thanks for the tip. Here is the updated indent file.

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/CflWb5jChQ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+unsubscribe@googlegroups.com.
sas.vim

Bram Moolenaar

unread,
Jun 28, 2018, 6:05:34 AM6/28/18
to vim...@googlegroups.com, Keny Hu

Keny Hu wrote:

> That makes sense. Thanks for the tip. Here is the updated indent file.

Thanks, I'll include this one.

--
hundred-and-one symptoms of being an internet addict:
126. You brag to all of your friends about your date Saturday night...but
you don't tell them it was only in a chat room.
Reply all
Reply to author
Forward
0 new messages