How do I concatenate cells and add extra text? - openoffice-calc

I'm very new to Calc but a relative veteran with Excel. Unfortunately I don't have the latter available to me. I'm attempting to create a new cell inline with the data I need to use like the below
AF Afghanistan
AL Albania
DZ Algeria
with an output in Column C like this
<option value="AF">Afghanistan</option>
I've tried to use the CONCATENATE function to no avail. Could someone point me in the right direction on how to achieve this in OpenOffice Calc (Version 3).
Thanks

I suppose it's a problem of escaping the quotes, since they delimit the "extra strings", too. Anyway, it should work with CONCATENATE, using this formula:
=CONCATENATE("<option value=""";A1;""">";B1;"</option>")
EDIT:
Sorry, every time messing up argument separators (with german l11n, semicolons instead of commata are used...) With an english (US) localisation, you need this version:
=CONCATENATE("<option value=""",A1,""">",B1,"</option>")
If doubling the qoutes around the first cell reference doesn't work, try to replace it with CHAR(34) (the decimal ASCII code for double quotes is 34, while 22 would be the hex value):
=CONCATENATE("<option value=",CHAR(34),A1,CHAR(34),">",B1,"</option>")

suppose 'AF' was in column A1 and 'Afghanistan' was in column C1, then this would produce the desired result
="<option value='"&A1&"'>"&C1&"</option>"
That code would give you this output
<option value='AF'>Afghanistan</option>

Related

IF OR AND excel formula

I am trying to write a formula where it will look for 8100, 8110, 8120, 8122, 8124, 8251, 8315, 8380 in one column (L) WHILE column (AA) needs to have either 0,1,2,3,4 then it should display "home". This is what I have so far
=IF(OR(L5="8100",L5="8110",L5="8120",L5="8122",L5="8124",L5="8251",L5="8315",L5="8380",AND(OR(AA5="0",AA5="1",AA5="2",AA5="3",AA5="4"),"HOME","NOT HOME"))
I need help implementing col (AA) with 0,1,2,3,4 filter.
so in the end for eg. if column (L) has 8100 AND col (AA) has 0 it should display "home", if it doesn't meet any one of those criteria it should display "not home". Hope my explanation makes sense any help is appreciated.
You need to move the AND to encompass both ORs, since AND is a standard function that requires two arguments. A formula like the following should work correctly:
=IF(AND(OR(L5="8100",L5="8110",L5="8120",L5="8122",L5="8124",L5="8251",L5="8315",L5="8380"),(OR(AA5="0",AA5="1",AA5="2",AA5="3",AA5="4"))),"HOME","NOT HOME").
Note that if you're working with numbers that aren't stored as text, you should remove the quotes, like so:
=IF(AND(OR(L5=8100,L5=8110,L5=8120,L5=8122,L5=8124,L5=8251,L5=8315,L5=8380),(OR(AA5=0,AA5=1,AA5=2,AA5=3,AA5=4))),"HOME","NOT HOME")
This should be possible to achieve with VLOOKUP.
Even better if that's the case look into the MATCH and INDEX combination: https://exceljet.net/articles/index-and-match

Extract multiple substrings of numbers of a specific length from string in Google Sheets

I'd need to split or extract only numbers made of 8 digits from a string in Google Sheets.
I've tried with SPLIT or REGEXREPLACE but I can't find a way to get only the numbers of that length, I only get all the numbers in the string!
For example I'm using
=SPLIT(lower(N2),"qwertyuiopasdfghjklzxcvbnm`-=[]\;' ,./!:##$%^&*()")
but I get all the numbers while I only need 8 digits numbers.
This may be a test value:
00150412632BBHBBLD 12458 32354 1312548896 ACT inv 62345471
I only need to extract "62345471" and nothing else!
Could you please help me out?
Many thanks!
Please use the following formula for a single cell.
Drag it down for more cells.
=INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "))=8,
SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "),"")),"where Col1 is not null ",0)))
Functions used:
QUERY
INDEX
TRANSPOSE
IF
LEN
SPLIT
REGEXREPLACE
If you only need to do this for one cell (or you have your heart set on dragging the formula down into individual cells), use the following formula:
=REGEXEXTRACT(" "&N2&" ","\s(\d{8})\s")
However, I suspect you want to process the eight-digit number out of all cells running N2:N. If that is the case, clear whatever will be your results column (including any headers) and place the following in the top cell of that otherwise cleared results column:
=ArrayFormula({"Your Header"; IF(N2:N="",,IFERROR(REGEXEXTRACT(" "&N2:N&" ","\s(\d{8})\s")))})
Replace the header text Your Header with whatever you want your actual header text to be. The formula will show that header text and will return all results for all rows where N2:N is not null. Where no eight-digit number is found, null will be returned.
By prepending and appending a space to the N2:N raw strings before processing, spaces before and after string components can be used to determine where only eight digits exist together (as opposed to eight digits within a longer string of digits).
The only assumption here is that there are, in fact, spaces between string components. I did not assume that the eight-digit number will always be in a certain position (e.g., first, last) within the string.
Try this, take a look at Example sheet
=FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8)
Or this to get them all.
=JOIN(" ,",FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8))
Explanation
SPLIT with the dilimiter set to " " space TRANSPOSE and FILTER TRANSPOSE(SPLIT(B2," ") with the condition1 set to LEN(TRANSPOSE(SPLIT(B2," "))) is = 8
JOIN the outputed column whith " ," to gat all occurrences of number with a length of 8
Note: to get the numbers with the length of N just replace 8 in the FILTER function with a cell refrence.
Using this on a cell worked just fine for me:
(cell_with_data)=REGEXEXTRACT(A1,"[0-9]{8}$")

Is there an error-proof way in google sheets to extract House numbers from address cell (street + house number) into another cell

In Sheet1!AK2:AK I have addresses in the following formats:
rotenkamper weg, 323, Kirchstieg 2345, Im Schleedörn 20b
I need the street names to export into Sheet2!C3:C, i.e:
rotenkamper weg, Kirchenstieg, Im Schleedörn
The House numbers have to go into Sheet2!D3:D.
I have researched and tried for hours but couldn't find a solution that could fetch the house numbers including the letter i.e. 20b or if the number is a range 24-27.
Also, I have huge trouble to get it to work when the street consist of two or more words.
Does anyone know an elegant solution for this?
Any help would be much appreciated. This will safe me weeks of data entry work.
Try this in Sheet2!C3:
=ARRAYFORMULA(
{
REGEXREPLACE(REGEXREPLACE(Sheet1!AK2:AK, "\s+\S*\d\S*\b", ""), ",+", ","),
IFNA(REGEXEXTRACT(Sheet1!AK2:AK, "\S+$"))
}
)
Explanation:
REGEXREPLACE(Sheet1!AK2:AK, "\s+\S*\d\S*\b", "") this one removes any "word" which has a digit in it. Al of these 323, 2345, 20b will be gone.
REGEXREPLACE(..., ",+", ",") cleans up any multiple consequent commas which may appear after removing in the first step. This will be a value for the first column.
IFNA(REGEXEXTRACT(Sheet1!AK2:AK, "\S+$")) this one just gets whatever is at the end of the address string from the last space to the end. This will be a value for the second column.
{value_for_the_first_column, value_for_the_second_column} placed in the C3 cell will populate C3 with value_for_the_first_column and D3 with value_for_the_first_column.
ARRAYFORMULA will do all of the above for every row.
Regex pattern could be refined if you provide more than one example of the address.

Removing quotes and spaces in SAS dataset

I am working in SAS EG and DI, facing a very peculiar problem.
When I look into a column of a dataset in SAS DI Studio or EG, it is appearing fine. But when I paste the data into notepad, some quotes and spaces are appearing.
The data which I am seeing in EG:
But the same data when copied into Notepad,
extra quotes and spaces are appearing like this(in 6th row):
I found this problem when I am using this field as a key in a join, the other related column values for 6th row are not going to the output as the match is failing for that 6th record.
I tried many things like tranwrd,dequote and compress but none of them is changing my result.
Can someone please help in understanding what the problem is and how can this be solved.
Take a look at what is in the column so that you can decide how to handle it. This query will show you both the character string and the Hexadecimal representation of the string.
proc sql;
select postcode,put(trim(postcode),$hex.) as hexcode,count(*) as nobs
from x
group by 1,2
;
quit;
So if you see hex characters like 0A, 0D, A0, 08 or other non-printable codes then you can figure out what is happening.
So you might see that you have POSTCODE='LS5 3BT' with HEXCODE='4C533520334254' for most of the records. But perhaps have some that look like the POSTCODE='LS5 3BT', but the value of HEXCODE is something like '0A4C533520334254' which would mean that you have a linefeed character at the beginning of the string. Or perhaps instead of space ('20'X) you have a tab ('09'X) in the middle of the string.

How do you get an if, then formula to calculate one of the answers?

I am trying to have a cell calculate the following, but I can't get it do the C5*$15 forumula, it just puts that info into the cell =IF(C5>8,"$125","C5*$15"). Please advise.
Remove the quotes from around "C5*$15". That's a string literal, so it will be printed exactly instead of evaluated in the FALSE case. You can also remove the $ and just use cell formatting to print the result as a dollar amount.
=IF(C5 > 8, 125, C5*15)
First, if you're working with numbers, don't use double quotes or dollar signs. Use numbers. Cell formatting will handle adding the currency symbol if your cell is formatted to be currency.
This works perfectly for me:
=IF(C5 > 8, 125, C5 * 15)