BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

Can I format Excel output from an sql procedure?

 

Something like

 

Proc sql;

select count(x) as count_num style={tagattr='format:#,##0'}

from y;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Batman wrote:

It gives me an error message

 

30 ods excel file="S:\HC\private\Temp\temp.xlsx"
31 options (embedded_titles='yes' embedded_footnotes='yes' sheet_name="Info"
32 sheet_interval='none');
33

NOTE: The data set WORK.Y has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.25 seconds
cpu time 0.11 seconds

34 Proc sql;

35 select count(x) as count_num style={tagattr='format:#,##0'}
_____
22
76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT, FROM, INFORMAT, INTO, LABEL, LEN,
LENGTH, TRANSCODE.

ERROR 76-322: Syntax error, statement will be ignored.

36 from y;


There's your answer. STYLE= in SQL is not allowed.

--
Paige Miller

View solution in original post

5 REPLIES 5
ballardw
Super User

Try it an see.

You would have to make sure that the output was directed to an ODS EXCEL file to see.

Batman
Quartz | Level 8

It gives me an error message

 

30 ods excel file="S:\HC\private\Temp\temp.xlsx"
31 options (embedded_titles='yes' embedded_footnotes='yes' sheet_name="Info"
32 sheet_interval='none');
33

NOTE: The data set WORK.Y has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.25 seconds
cpu time 0.11 seconds

34 Proc sql;

35 select count(x) as count_num style={tagattr='format:#,##0'}
_____
22
76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT, FROM, INFORMAT, INTO, LABEL, LEN,
LENGTH, TRANSCODE.

ERROR 76-322: Syntax error, statement will be ignored.

36 from y;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
37 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
2 The SAS System 19:20 Wednesday, March 1, 2023

real time 0.00 seconds
cpu time 0.00 seconds

38
39 ods excel close;
NOTE: Writing EXCEL file: S:\HC\private\Temp\temp.xlsx

SASKiwi
PROC Star

I don't think STYLE is a valid option on a SELECT statement. PROC SQL isn't designed to do any more than simple reporting.

 

Just add a PROC REPORT or similar reporting PROC after your PROC SQL step creates the required table to report on.

PaigeMiller
Diamond | Level 26

@Batman wrote:

It gives me an error message

 

30 ods excel file="S:\HC\private\Temp\temp.xlsx"
31 options (embedded_titles='yes' embedded_footnotes='yes' sheet_name="Info"
32 sheet_interval='none');
33

NOTE: The data set WORK.Y has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.25 seconds
cpu time 0.11 seconds

34 Proc sql;

35 select count(x) as count_num style={tagattr='format:#,##0'}
_____
22
76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT, FROM, INFORMAT, INTO, LABEL, LEN,
LENGTH, TRANSCODE.

ERROR 76-322: Syntax error, statement will be ignored.

36 from y;


There's your answer. STYLE= in SQL is not allowed.

--
Paige Miller
Reeza
Super User
I'd also recommend just trying a comma format and seeing if that worked 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 574 views
  • 2 likes
  • 5 in conversation