BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
u38109150
Fluorite | Level 6

I create a repport with a stored process.
I use SQL.
I run this process with reports on in sas add-in for Excel.
In this reports are numbers beginnen with zero, like 000048383.
I will keep this zeros.
I think i should slove this in the stored proces tab "Data Sources and Targets. But I do'nt know how.

 

My code  is like this.

VESTIGINGSNR is like 000047178622 format  $12.

 

PROC SQL;
SELECT DISTINCT
FORMULE.HANDELSNAAM label="Handelsnaam",
FORMULE.NAW label="Adres",
FORMULE.VESTIGINGSNUMMER AS VESTIGINGSNR label="Vestigingsnummer"
FROM AIDDWH.REF_FORMULEBEDRIJF AS FORMULE
;
QUIT;

1 ACCEPTED SOLUTION

Accepted Solutions
12 REPLIES 12
MichaelLarsen
SAS Employee
Just add FORMAT=Z9. ie.:
label="Vestigingsnummer" format=z9.
u38109150
Fluorite | Level 6

Thank you for replying. This doesn't help. My input (VESTIGINGSNUMMER)  is a character ($12.). Excel makes it a number, but it must stay a character.

MichaelLarsen
SAS Employee

I have not tested it, but can you try this:

 

PROC SQL;
SELECT DISTINCT
FORMULE.NAAM label="Nalevingssoort",
FORMULE.HANDELSNAAM label="Handelsnaam",
FORMULE.NAW label="Adres",
catt("'",FORMULE.VESTIGINGSNUMMER AS VESTIGINGSNR) label="Vestigingsnummer"
FROM AIDDWH.REF_FORMULEBEDRIJF AS FORMULE
;
QUIT;

I am assuming that the leading zeroes are already present in the input table.

You can also take a look at the ODS EXCEL documentation it offers you more flexibility:

https://documentation.sas.com/?docsetId=odsug&docsetTarget=p09n5pw9ol0897n1qe04zeur27rv.htm&docsetVe...

 

 

MichaelLarsen
SAS Employee

sorry there is a syntax error, try this:

 

PROC SQL;
SELECT DISTINCT
FORMULE.NAAM label="Nalevingssoort",
FORMULE.HANDELSNAAM label="Handelsnaam",
FORMULE.NAW label="Adres",
catt("'",FORMULE.VESTIGINGSNUMMER) AS VESTIGINGSNR label="Vestigingsnummer"
FROM AIDDWH.REF_FORMULEBEDRIJF AS FORMULE
;
QUIT;
Tom
Super User Tom
Super User

Why doesn't it know that the variable is character and keep the results in Excel as character?

Is there something broken in the SAS Add-in to Excel?

MichaelLarsen
SAS Employee
No, I think Excel is just trying to be helpful.
You can try and enter the value 000048383 into an empty cell and you will see the same problem.
Adding the quote as the first character forces Excel to regard the value as a character value.
Tom
Super User Tom
Super User

@MichaelLarsen wrote:
No, I think Excel is just trying to be helpful.
You can try and enter the value 000048383 into an empty cell and you will see the same problem.
Adding the quote as the first character forces Excel to regard the value as a character value.

If I create an Excel file from normal SAS using tools like PROC EXPORT or XLSX engine on a libname it knows the variable is character and I don't have to play tricks with the values to get Excel to display it properly.

And in Excel itself if I set the type for a cell as text and enter a value with leading zeros it displays them properly.

 

So the question is why does pulling data with the Excel Add-In not also know that the variable being pulled is character?

u38109150
Fluorite | Level 6

Yes Thank you this works.

And I don't see the qoute (') in the Excel output.

TimBeese
SAS Employee

This is a tricky one where there are two schools of thought on how this should work.

 

A) The data is marked as character data, so when it goes into Excel, we should treat it as text.  This is the ideal solution for the user who wants to see their data in Excel exactly as they see it in their generated results.  

 

B) The data is marked as character data, but Excel can interpret it differently, we should let Excel interpret it.  This is the ideal solution for someone who wants to continue to explore their data with Excel.  If Excel is able to interpret the data as a number or date, then the user can use Excel formulas to continue to work with their data.

 

As with many of these situations, we decided to add an option in the SAS Add-In for Microsoft Office to handle this.  If you set your result format to SAS Report Xml, then the add-in has control over the format of the cell.  We decide whether to force the format to Text or leave it as General based on an option.

 

Here's how to get to this option:

From the SAS tab on the ribbon, go to Tools->Options.  On the options dialog go to the Results page and scroll to the bottom.  There's a group called "Tables".  Inside of that group is an option called "Allow Excel to interpret value types in SAS Report tables".  By changing the value of this option, you can get the results you desire the next time you open a new instance of that stored process.

 

If you have content already inserted, then you'll need to either remove it and insert a new instance of the stored process.  Or change the settings for that content.  You can do this by setting the format of the cells to Text manually.  Then, while that content is selected, choose SAS->Properties.  On the Properties dialog, choose the Appearance tab and check "Preserve Excel number formatting".  This will instruct us to NOT change the format on the cells when refreshing this content.  You can set it up how you want it and the Add-In will not change it during a refresh.

 

Hope this helps!

Tim Beese

u38109150
Fluorite | Level 6

Yes, thank you, this helps too.

This is even a better solution.

My Users need to do the same thing. That won’t be a problem I suppose.

Tom
Super User Tom
Super User

Much better answer.

Tom
Super User Tom
Super User

You tagged the wrong answer as the solution.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 8657 views
  • 4 likes
  • 4 in conversation