- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-07-2011 11:16 AM
(5647 views)
is there some advice for "code formatter/beautifier", to help line-up the SAS
code, to improve readability in SAS?
code, to improve readability in SAS?
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Upgrade to EGuide 4.3. there is one built in to it. Check the SAS/Dummy blog archives for an article on it.
http://blogs.sas.com/sasdummy/
http://blogs.sas.com/sasdummy/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Specific topics on the blog:
http://blogs.sas.com/sasdummy/index.php?/archives/188-Hope-for-ugly-programs.html
http://blogs.sas.com/sasdummy/index.php?/archives/233-The-SAS-code-formatter-more-than-a-pretty-face...
Enjoy!
Chris
http://blogs.sas.com/sasdummy/index.php?/archives/188-Hope-for-ugly-programs.html
http://blogs.sas.com/sasdummy/index.php?/archives/233-The-SAS-code-formatter-more-than-a-pretty-face...
Enjoy!
Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Chris,
BTW, I found that Ctrl+I does not format proc SQL.
Sincerely,
SPR
BTW, I found that Ctrl+I does not format proc SQL.
Sincerely,
SPR
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It should format PROC SQL, at least with basic indentation.
For me, it turns this:
[pre]
proc sql;
create table work.out as
select age,
(height/weight) as ratio
from sashelp.class where age>12;
quit;
[/pre]
into this:
[pre]
proc sql;
create table work.out as
select age,
(height/weight) as ratio
from sashelp.class where age>12;
quit;
[/pre]
For me, it turns this:
[pre]
proc sql;
create table work.out as
select age,
(height/weight) as ratio
from sashelp.class where age>12;
quit;
[/pre]
into this:
[pre]
proc sql;
create table work.out as
select age,
(height/weight) as ratio
from sashelp.class where age>12;
quit;
[/pre]
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Chris,
This is a real life example. I've got this code from a macro that produces SQL code in LOG (options mprint):
[pre]
proc SQL;
create view pd as
select
case
when dlq = 1 and iltv=0 and RB < 555 then 100*1+0 when dlq = 1 and iltv=0 and
555 <= RB < 634 then 100*1+1 when dlq = 1 and iltv=0 and 634 <= RB < 672 then 100*1+2 when dlq = 1 and iltv=0 and 672 <= RB then
100*1+3 when dlq = 1 and iltv=1 and RB < 558 then 100*1+50+0 when dlq = 1 and iltv=1 and 558 <= RB < 644 then 100*1+50+1 when dlq =
1 and iltv=1 and 644 <= RB < 707 then 100*1+50+2 when dlq = 1 and iltv=1 and 707 <= RB < 732 then 100*1+50+3 when dlq = 1 and
iltv=1 and 732 <= RB then 100*1+50+4 when dlq = 2 and iltv=0 and RB < 646 then 100*2+0 when dlq = 2 and iltv=0 and 646 <= RB then
100*2+1 when dlq = 2 and iltv=1 and RB < 556 then 100*2+50+0 when dlq = 2 and iltv=1 and 556 <= RB < 631 then 100*2+50+1 when dlq =
2 and iltv=1 and 631 <= RB then 100*2+50+2 when dlq = 3 then 100*dlq when dlq = 4 then 100*dlq when dlq > 4 then 500 else 999
end as pnam label="RC75 RB Pools",
date, SUM(PD*N) as Nb, SUM(N) as N,
SUM(PD*N)/SUM(N)*10000 as bps label="PD, bps" format=6.1,
SUM(Bal) as Bal format 15.0
from _w.ds75_&t
group by date, pnam
order by date, pnam
;quit;
[/pre]
Automatic identation does not help in this case. All Case clauses are messed.
Sincerely,
SPR
This is a real life example. I've got this code from a macro that produces SQL code in LOG (options mprint):
[pre]
proc SQL;
create view pd as
select
case
when dlq = 1 and iltv=0 and RB < 555 then 100*1+0 when dlq = 1 and iltv=0 and
555 <= RB < 634 then 100*1+1 when dlq = 1 and iltv=0 and 634 <= RB < 672 then 100*1+2 when dlq = 1 and iltv=0 and 672 <= RB then
100*1+3 when dlq = 1 and iltv=1 and RB < 558 then 100*1+50+0 when dlq = 1 and iltv=1 and 558 <= RB < 644 then 100*1+50+1 when dlq =
1 and iltv=1 and 644 <= RB < 707 then 100*1+50+2 when dlq = 1 and iltv=1 and 707 <= RB < 732 then 100*1+50+3 when dlq = 1 and
iltv=1 and 732 <= RB then 100*1+50+4 when dlq = 2 and iltv=0 and RB < 646 then 100*2+0 when dlq = 2 and iltv=0 and 646 <= RB then
100*2+1 when dlq = 2 and iltv=1 and RB < 556 then 100*2+50+0 when dlq = 2 and iltv=1 and 556 <= RB < 631 then 100*2+50+1 when dlq =
2 and iltv=1 and 631 <= RB then 100*2+50+2 when dlq = 3 then 100*dlq when dlq = 4 then 100*dlq when dlq > 4 then 500 else 999
end as pnam label="RC75 RB Pools",
date, SUM(PD*N) as Nb, SUM(N) as N,
SUM(PD*N)/SUM(N)*10000 as bps label="PD, bps" format=6.1,
SUM(Bal) as Bal format 15.0
from _w.ds75_&t
group by date, pnam
order by date, pnam
;quit;
[/pre]
Automatic identation does not help in this case. All Case clauses are messed.
Sincerely,
SPR
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the example. No, the formatter doesn't dive deep into these constructs (such as CASE). But I'll pass this on to the development team!
Chris
Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Long time, but has anything come of this? Auto-formatting SQL syntax would make the Formatting feature so much more useful. I regularly use Poor SQL - Instant Free and Open-Source T-SQL Formatting to do this task, but the tool does not handle ampersand (macro) references or comments well at all.