SPSS print a statement to the ouput window - spss

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.

Related

Understanding the output of with_stdout

Acordding to the documentation of maxima, with_stdout is a function that evaluates some expressions and writes the output according to this expressions to a file f. I tried to use this function with a simple example:
with_stdout ("data.txt", for x:0 thru 10 do print (x, x^2, x^3))$
But the output look like this:
<mth><n>0</n><st> </st><n>0</n><st> </st><n>0</n><st> </st></mth><mth><n>1</n><st> </st><n>1</n><st> </st><n>1</n><st> </st></mth><mth><n>2</n><st> </st><n>4</n><st> </st><n>8</n><st> </st></mth><mth><n>3</n><st> </st><n>9</n><st> </st><n>27</n><st> </st></mth><mth><n>4</n><st> </st><n>16</n><st> </st><n>64</n><st> </st></mth><mth><n>5</n><st> </st><n>25</n><st> </st><n>125</n><st> </st></mth><mth><n>6</n><st> </st><n>36</n><st> </st><n>216</n><st> </st></mth><mth><n>7</n><st> </st><n>49</n><st> </st><n>343</n><st> </st></mth><mth><n>8</n><st> </st><n>64</n><st> </st><n>512</n><st> </st></mth><mth><n>9</n><st> </st><n>81</n><st> </st><n>729</n><st> </st></mth><mth><n>10</n><st> </st><n>100</n><st> </st><n>1000</n><st> </st></mth>
instead of writting a table with three columns as it is supposed to do.
I don't even understand the first output. What I am missunderstanding or missing here?
--
It seems there is a bug triggered by Wxmaxima, I don't know if it is on maxima aswell.
Regards.
Apparently wxMaxima overrides the default print function to generate XML tags (stuff like <foo> ... </foo>) which wxMaxima uses to indicate how stuff is displayed. I don't know if it's possible to directly call the default print function in wxMaxima; maybe, maybe not.
I can see a few options. (1) Call grind instead, which outputs the so-called 1-dimensional output. That's probably more suitable for file output anyway.
(2) Call printf, e.g. printf(true, "~a, ~a, ~a~%", x, x^2, x^3). printf recognizes many output options, as described by ? printf. It's possible printf calls are also intercepted by wxMaxima, I haven't tried it.
(3) Use the plain text, console Maxima interface, then print is sure to be the default.

How to make the output of Maxima cleaner?

I want to make use of Maxima as the backend to solve some computations used in my LaTeX input file.
I did the following steps.
Step 1
Download and install Maxima.
Step 2
Create a batch file named cas.bat (for example) as follows.
rem cas.bat
echo off
set PATH=%PATH%;"C:\Program Files (x86)\Maxima-5.31.2\bin"
maxima --very-quiet -r %1 > solution.tex
Save the batch in the same directory in which your input file below exists. It is just for the sake of simplicity.
Step 3
Create the input file named main.tex (for example) as follows.
% main.tex
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\def\f(#1){(#1)^2-5*(#1)+6}
\begin{document}
\section{Problem}
Evaluate $\f(x)$ for $x=\frac 1 2$.
\section{Solution}
\immediate\write18{cas "x: 1/2;tex(\f(x));"}
\input{solution}
\end{document}
Step 4
Compile the input file with pdflatex -shell-escape main and you will get a nice output as follows.
!
Step 5
Done.
Questions
Apparently the output of Maxima is as follows. I don't know how to make it cleaner.
solution.tex
1
-
2
$${{15}\over{4}}$$
false
Now, my question are
how to remove such texts?
how to obtain just \frac{15}{4} without $$...$$?
(1) To suppress output, terminate input expressions with dollar sign (i.e. $) instead of semicolon (i.e. ;).
(2) To get just the TeX-ified expression sans the environment delimiters (i.e. $$), call tex1 instead of tex. Note that tex1 returns a string, which you have to print yourself (while tex prints it for you).
Combining these ideas with the stuff you showed, I think your program could look like this:
"x: 1/2$ print(tex1(\f(x)))$"
I think you might find the Maxima mailing list helpful. I'm pretty sure there have been several attempts to create a system such as the one you describe. You can also look at the documentation.
I couldn't find any way to completely clean up Maxima's output within Maxima itself. It always echoes the input line, and always writes some whitespace after the output. The following is an example of a perl script that accomplishes the cleanup.
#!/usr/bin/perl
use strict;
my $var = $ARGV[0];
my $expr = $ARGV[1];
sub do_maxima_to_tex {
my $m = shift;
my $c = "maxima --batch-string='exptdispflag:false; print(tex1($m))\$'";
my $e = `$c`;
my #x = split(/\(%i\d+\)/,$e); # output contains stuff like (%i1)
my $f = pop #x; # remove everything before the echo of the last input
while ($f=~/\A /) {$f=~s/\A .*\n//} # remove echo of input, which may be more than one line
$f =~ s/\\\n//g; # maxima breaks latex tokens in the middle at end of line; fix this
$f =~ s/\n/ /g; # if multiple lines, get it into one line
$f =~ s/\s+\Z//; # get rid of final whitespace
return $f;
}
my $e1 = do_maxima_to_tex("diff($expr,$var,1)");
my $e2 = do_maxima_to_tex("diff($expr,$var,2)");
print <<TEX;
The first derivative is \$$e1\$. Differentiating a second time,
we get \$$e2\$.
TEX
If you name this script a.pl, then doing
a.pl z 3*z^4
outputs this:
The first derivative is $12\,z^3$. Differentiating a second time,
we get $36\,z^2$.
For the OP's application, a script like this one could be what is invoked by the write18 in the latex file.
If you really want to use LaTeX then the maxiplot package is the answer. It provides a maxima environment inside of which you enter Maxima commands. When you process your LaTeX file a Maxima batch file is generated. Process this file with Maxima and process your LaTeX file again to typeset the equations generated by Maxima.
If you would rather have 2D math input with live typesetting then use TeXmacs. It is a cross-platform document authoring environment (a word processor on steroids if you like) that includes plugins for Maxima, Mathematica and many more scientific computing tools. If you need to or are not satisfied with the typesetting, you can export your document to LaTeX.
I know this is a very old post. Excellent answers for the question asked by OP. I was using --very-quiet -r options on the command line for a long time like OP, but in maxima version 5.43.2 they behave differently. See maxima command line v5.43 is behaving differently than v5.41. I am answering this question with a cross reference because when incorporating these answers in your solutions, make sure the changes in behavior of those command line flags are also incorporated.

Easiest way to remove Latex tag (but not its content)?

I am using TeXnicCenter to edit a LaTeX document.
I now want to remove a certain tag (say, emph{blabla}} which occurs multiple times in my document , but not tag's content (so in this example, I want to remove all emphasization).
What is the easiest way to do so?
May also be using another program easily available on Windows 7.
Edit: In response to regex suggestions, it is important that it can deal with nested tags.
Edit 2: I really want to remove the tag from the text file, not just disable it.
Using a regular expression do something like s/\\emph\{([^\}]*)\}/\1/g. If you are not familiar with regular expressions this says:
s -- replace
/ -- begin match section
\\emph\{ -- match \emph{
( -- begin capture
[^\}]* -- match any characters except (meaning up until) a close brace because:
[] a group of characters
^ means not or "everything except"
\} -- the close brace
and * means 0 or more times
) -- end capture, because this is the first (in this case only) capture, it is number 1
\} -- match end brace
/ -- begin replace section
\1 -- replace with captured section number 1
/ -- end regular expression, begin extra flags
g -- global flag, meaning do this every time the match is found not just the first time
This is with Perl syntax, as that is what I am familiar with. The following perl "one-liners" will accomplish two tasks
perl -pe 's/\\emph\{([^\}]*)\}/\1/g' filename will "test" printing the file to the command line
perl -pi -e 's/\\emph\{([^\}]*)\}/\1/g' filename will change the file in place.
Similar commands may be available in your editor, but if not this will (should) work.
Crowley should have added this as an answer, but I will do that for him, if you replace all \emph{ with { you should be able to do this without disturbing the other content. It will still be in braces, but unless you have done some odd stuff it shouldn't matter.
The regex would be a simple s/\\emph\{/\{/g but the search and replace in your editor will do that one too.
Edit: Sorry, used the wrong brace in the regex, fixed now.
\renewcommand{\emph}[1]{#1}
any reasonably advanced editor should let you do a search/replace using regular expressions, replacing emph{bla} by bla etc.

How to print Java code on A3 page avoiding line-wrapping

I have to print Java code that some times reaches 300 columns (characters per line) in A3 paper and whatever editor I use (e.g. textmate) wraps the lines in order to fit in A4 paper.
Any suggestions?
cheers,
Asterios
Your editor undoubtably has either a Page Setup dialog or a Preferences dialogue as part of the Print Dialogue which will allow you to set the Paper Size to use for printing.
Even Notepad supports this
I finally made it to print using enscript. Here is the command I used to print Java code into PDF (and the used the pdf to print).
enscript -r -Ejava -M A3 -C -f "Courier8" input.java -o - | ps2pdf - output.pdf
where:
-r prints in landscape mode
-C prints the line numbers
-f changes the font and size
-M sets the output media to A3 (default is A4)
-Ejava adds syntax highlighting (you can also use --color if you need
colors in syntax highlighting but
they are not nicely printed in
greyscale)
It seems unlikely that every editor tries to format for A4. Which other editors have you tried? Does textmate not have a page size option? (Hmm... seems not)
Try a different editor that does let you set page size. Word, even.

Regular expressions: How do I grab a block of text using regex? (in ruby)

I'm using ruby and I'm trying to find a way to grab text in between the {start_grab_entries} and {end_grab_entries} like so:
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
Something like so:
$1 => "i want to grab
the text that
you see here in
the middle"
So far, I tried this as my regular expression:
\{start_grab_entries}(.|\n)*\{end_grab_entries}
However, using $1, that gives me a blank. Do you know what I can do to grab that block of text in between the tags correctly?
There is a better way to allow the dot to match newlines (/m modifier):
regexp = /\{start_grab_entries\}(.*?)\{end_grab_entries\}/m
Also, make the * lazy by appending a ?, or you might match too much if more than one such section occurs in your input.
That said, the reason why you got a blank match is that you repeated the capturing group itself; therefore you only caught the last repetition (in this case, a \n).
It would have "worked" if you had put the capturing group outside of the repetition:
\{start_grab_entries\}((?:.|\n)*)\{end_grab_entries\}`
but, as said above, there is a better way to do that.
I'm adding this because often we're reading data from a file or data-stream where the range of lines we want are not all in memory at once. "Slurping" a file is discouraged if the data could exceed the available memory, something that easily happens in production corporate environments. This is how we'd grab lines between some boundary markers as the file is being scanned. It doesn't rely on regex, instead using Ruby's "flip-flop" .. operator:
#!/usr/bin/ruby
lines = []
DATA.each_line do |line|
lines << line if (line['{start_grab_entries}'] .. line['{end_grab_entries}'])
end
puts lines # << lines with boundary markers
puts
puts lines[1 .. -2] # << lines without boundary markers
__END__
this is not captured
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
this is not captured either
Output of this code would look like:
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
i want to grab
the text that
you see here in
the middle
string=<<EOF
blah
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
blah
EOF
puts string.scan(/{start_grab_entries}(.*?){end_grab_entries}/m)

Resources