I am trying to convert the float number to European formats.
I tried to assign a format like below but it's not converting properly.
works fine:
cell.z = "#,###,##0.00";
does not work:
cell.z = "#.###.##0,000"
cell.z = "# ### ##0,000";
If it is not possible can I at least declare decimal values as comma (,) separator?
Can you please provide some pointers?
We do not need to add any special format to the number. I solved the problem by converting it to a number (Not String), excel will open based on user settings. No additional development is required.
Related
I am reading data from an excel file in SAS and inserting the values to an oracle table. The oracle table has a numeric column. If the excel file has numbers, it works fine. But if the column is left blank in the excel file, it is read as a character value and insertion to oracle fails.
Is it possible to convert the column to numeric if its is blank, but read it as is if its has a number?
Thanks!
Let's assume that SAS is reading this column as a character and you cannot convert it directly within the file. This happens sometimes: maybe you don't have authorization to do it, or maybe it's just not working like you're expecting. SAS can go from character to numeric and numeric to character with two functions: input() and put().
Going from Character to Numeric: input()
input() is for changing character data into numbers.
This is great for reading in dates, currency, comma-separated numbers, etc. If you need your data as a number, use this function. Its syntax is:
num_var = input(char_var, informat.);
In your case, let's say we always expect numbers to be here even if it's missing. We'll use the 8. informat for our variable of interest, my_var.
data want;
set have_excel(rename=(my_var = my_var_char) );
my_var = input(my_var_char, 8.);
drop my_var_char;
run;
Note that we need to create a new variable. We rename the variable of interest to something else, then create a new version of the variable of interest that is a number. In SAS, just like many other languages and database systems, when a variable is declared as a character or number, it is always a character or a number.
Going from Numeric to Character: put()
put() is for putting a number to a character or a character to another character.
This is great for converting SAS dates to characters, adding custom formats, converting a character to another character, etc. The syntax is:
char_var = put(num_var, format.);
OR:
char_var = put(char_var, format.);
Note the previous use case: with put(), you can convert characters to other characters. This is very handy for standardizing values or even merging data using a format.
For example: let's convert a number to a comma-separated character number.
data want;
char_number = put(1234, comma.);
run;
Output:
char_number
1,234
Below case statement worked for me.
case
when missing(input(cats(COLUMN_VALUE), best8.)) THEN input(cats(COLUMN_VALUE), best8.)
when not missing(input(cats(COLUMN_VALUE), best8.)) THEN input(cats(COLUMN_VALUE), best8.)
end as COLUMN_VALUE
I looking for a number format that is locale-independent.
Let's say that I want that my Excel file use an a character as a thousand separator and a b character as a decimal separator on every computer (so this question is not about local Excel settings). The second wish is that the number has always two decimal places.
Can I do this only with a number format without VB code?
After some attempts, I came to this format: ###\a###\a##0\b.00.
1234567.89 > 1a234a567b.89
The problems are:
I must repeat ###\a section and I can not get rid of dot decimal separator (the decimal places are not taken into account without the dot character).
Can I do this only with a number format without VB code?
No.
Even if you can get your separator characters inserted, you will not be able to remove the decimal separator.
The decimal separator is displayed in the cell whenever it is included in custom number display format settings.
I have been using Excel VBA for a while now and I have come across a problem that I have never encountered before. I am using someone elses computer that is set up as Polish, so the decimal separator is set to comma. But even when I had my computer set up similarly in the past I did not have any problem.
This current project creates a drawing in Visio.
So,
I have a variable of type double that is calculated as pgeWidth = 550 / 1.4
What I would expect is that VBA would calculate pageWidth = 392.857...
However what VBA is doing is pgeWidth = 392,857... If I put a break in and check the value of pgeWidth it shows the value with a comma separator. pgeWidth is then set to the page width property in Visio which thinks it should be 392857.... mm wide which obviously gives an error.
Why is VBA using a comma decimal separator instead of a point?
If you want to pass the value further with point, consider converting variable to a string and then replacing comma with point:
pgeWidth = replace(CStr(pgeWidth), ",",".")
Note: There are questions asking the opposite, I am asking how to convert original Excel date that has underlying numerical value (for example, 27 May 1997 would correspond to 35577) into yyyymmdd format.
I have an Excel file where originally the dates were entered manually. Excel displays them as dates, but as you know they have a numeric underlying value. I.e., in the example I gave above, if you export this date into any other statistical software (i.e., Matlab or R), the value would be the underlying numeric counterpart.
What I need to do is to convert these "original" Excel dates into yyyymmdd format and then export them elsewhere.
Any suggestions are welcome.
See if this works for you -
%// For demo couple of values are assumed, but these are the values
%// that you have got from excel file
numerical_vals = [35577 ; 35579]
date_array = datevec(numerical_vals);
date_array(:,1) = date_array(:,1)+1900;
out = datestr(date_array,'yyyy/mm/dd')
Output -
out =
1997/05/27
1997/05/29
First, you should check your date setting in your computer.
Navigate to :
Control Panel -> Clock and Region -> Region-change date, time or
number formats -> Additional Settings -> Date
There change the Short date under Date formats (yyyy/MM/dd), then apply them in both windows and click ok. Restart the excel and it should work!
If it still doesn't work, you can check the format cell in excel, and convert the cells into dates.
Besides, there's a function in R called as.Date(x, format, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), which also could work.
I use the print function to export a Cell Value to csv file. I use this macro on several PCs with different Localization Settings. The problem i am experiencing is, that on some PCs the Output is 4,11 and 4.11 on others. Is there any Format Method, that allows me always write a Number with a semicolon as decimal Seperator?
As far as I'm aware, there is no format method for changing the decimal separator. Instead your options are temporarily telling Excel to use a special character or using Replace().
Application.UseSystemSeparators = False
Application.DecimalSeparator = ";"
Print #1, rngValue.Text
Or
Print #1, Replace(rngValue, ",", ";")
In either case you then have a problem, when reading the numbers back in, of converting them back to the correct character so they are considered numbers.
A better question might be how do programmers in places that use the comma as the decimal separator handle decimal values in CSV files?