How do I print multiple variables on the same line in the DolphinDB GUI? - printing

I want to print the following variables on the same line:
print('pre_date', pre_date, 'date', date)
Execute the script in GUI and the output is:
pre_date
2021.01.06T00:00:00.000000000
date
2021.01.06T00:00:00.000000000
The result is displayed on 4 separate lines. How to output them on the same line?

You can use the plus sign (“+”) to concatenate strings together and print it out:
print('pre_date:' + string(pre_date) + ',date:' + string(date))

Related

How to print on same line using two print statement in lua

Example:
Input:
Print("hello")
Print("hi")
Output:
hello
hi
I want to output both "hello" and "hi" on the same line like hellohi without using concatenation.
You can achieve what you want using io.write(). This does not write a line break by default.
io.write("hello")
io.write("hi")
Output:
hellohi
To add line breaks simply add \n to your io.write e.g.
io.write("hello\nhi")
output:
hello
hi
Moreover, if you want to write a variable with a string:
Age = 18
print("Age: " .. Age)
where the .. concatenates them together.

Split or tokenize within Stata program with using statement?

I am trying to use a program to speed up a repetitive Stata task. This is the first part of my program:
program alphaoj
syntax [varlist] , using(string) occ_level(integer) ind_level(integer)
import excel `using', firstrow
display "`using'"
split "`using'", parse(_)
local year = `2'
display "`year'"
display `year'
When I run this program, using the line alphaoj, ind_level(4) occ_level(5) using("nat4d_2002_dl.xls"), I receive the error factor-variable and time-series operators not allowed r(101);
I am not quite sure what is being treated as a factor or time series operator.
I have replaced the split line with tokenize, and the parse statement with parse("_"), and I continue to run into errors. In that case, it says _ not found r(111);
Ideally, I would have it take the year from the filename and use that year as the local.
I am struggling with how I should perform this seemingly simple task.
An error is returned because the split command only accepts string variables. You can't pass a string directly to it. See help split for more details.
You can achieve your goal of extracting the year from the filename and storing that as a local macro. See below:
program alphaoj
syntax [varlist], using(string)
import excel `using', firstrow
gen stringvar = "`using'"
split stringvar, parse(_)
local year = stringvar2
display `year'
end
alphaoj, using("nat4d_2002_dl.xls")
The last line prints "2002" to the console.
Alternative solution that avoids creating an extra variable:
program alphaoj
syntax [varlist], using(string)
import excel `using', firstrow
local year = substr("`using'",7,4)
di `year'
end
alphaoj, using("nat4d_2002_dl.xls")
Please note that this solution is reliant on the Excel files all having the exact same character structure.

Datastage defining ; as delimiter and !; as not a delimeter

I have a data txt file which looks like following
1;2;3;4;5
1;2;3!;4;4;5
I'm expecting my output should look like as follows after reading the sequential file.
1 2 3 4 5
1 2 34 4 5
since there is only possiblity to define what's the delimiter in Datastage it don't detect !; as not a delimiter.
Could someone let me how can i overcome this problem.
One option could be to import it as a single column and and remove the "!," in a transformer and then do a column import stage dividing up the columns.
Read data as a single string. Convert "!;" to "" using Ereplace() or Change() function. Then parse using Transformer loop or Column Import stage.

SPSS print a statement to the ouput window

What syntax do I use to print "hello world" in the output window?
I simply want to specify the text in the syntax and have it appear in the output.
You need the title command:
title 'this is my text'.
Note that the title can be up to 256 bytes long.
Alternatively, you could use ECHO also. ECHO is useful for debugging macro variable assignements where as TITLE is useful for neat/organised presentation of your tables with intension to perhaps export output results.
If you want to write arbitrary text in its own block in the Viewer rather than having it stuck in a log block, use the TEXT extension command (Utilities > Create text output). You can even include html markup in the text.
If you don't have this extension installed, you can install it from the Utilities menu in Statistics 22 or 23 or the Extensions menu in V24.
example:
TEXT "The following output is very important!"
/OUTLINE HEADING="Comment" TITLE="Comment".
Outfile here is used in an ambiguous way. The prior two answers (the TITLE and ECHO commands) simply print something to the output window. One additional way to print to the output window is the PRINT command.
DATA LIST FREE / X.
BEGIN DATA
1
2
END DATA.
PRINT /'Hello World'.
EXECUTE.
If you do that set of syntax you will actually see that 'Hello World' is printed twice -- one for each record in the dataset. So one way to only print one line is to wrap it in a DO IF statement and only select the first row of data.
DO IF $casenum=1.
PRINT /'Hello World'.
END IF.
EXECUTE.
Now how is this any different than the prior two commands? Besides aesthetic looks in the output window, PRINT allows you to save an actual text file of the results via the OUTFILE parameter, which is something neither of the prior two commands allows.
DO IF $casenum=1.
PRINT OUTFILE='C:\Users\Your Name\Desktop\Hello.txt' /'Hello World'.
END IF.
EXECUTE.

GNU-M4: Strip empty lines

How can I strip empty lines (surplus empy lines) from an input file using M4?
I know I can append dnl to the end of each line of my script to suppress the newline output, but the blank lines I mean are not in my script, but in a data file that is included (where I am not supposed to put dnl's).
I tried something like that:
define(`
',`')
(replace a new-line by nothing)
But it didn't work.
Thanks.
I use divert() around my definitions :
divert(-1) will suppress the output
divert(0) will restore the output
Eg:
divert(-1)dnl output supressed starting here
define(..)
define(..)
divert(0)dnl normal output starting here
use_my_definitions()...
I understand your problem to be a data file with extra line breaks, meaning that where you want to have the pattern data<NL>moredata you have things like data<NL><NL>moredata.
Here's a sample to cut/paste onto your command line that uses here documents to generate a data set and runs an m4 script to remove the breaks in the data set. You can see the patsubst command replaces every instance of one or more newlines in sequence (<NL><NL>*) with exactly one newline.
cat > data << -----
1, 2
3, 4
5, 6
7, 8
9, 10
11, 12
e
-----
m4 << "-----"
define(`rmbreaks', `patsubst(`$*', `
*', `
')')dnl
rmbreaks(include(data))dnl
-----

Resources