Extracting some of the digits of a number - spss

I'm trying to compute a new variable with the first four digits of a numeric variable I have.
To begin with, I changed the existing numeric variable to String, and then used the following code in the syntax editor:
COMPUTE New_Varible = NUMBER(SUBSTR(Student_ID,1,2),f4) .
EXECUTE .
When I run the first line of code, it goes to the Transformation Pending mode, and a numeric scale variable is created with missing values (dots). But when I run the execute, the new scale variable suddenly changes to nominal, without showing any values. I've also tried it with the 'CHAR.SUBSTR' command, but to no avail.
P.S.
I'm using SPSS version 26, 64-bit on Windows 10.

I assume your problem started when you changed your number variable into string. If the string is wider thant the number, you may have some extra spaces to the left of the digits in the string. So your command is reading spaces instead of digits, and then fails to turn them into a number.
This corrected command should hopefully do the trick, using ltrim to remove the extra spaces before reading the digits (also note that you only read two characters with your original command - corrected here to four instead):
COMPUTE New_Varible = NUMBER(CHAR.SUBSTR(ltrim(Student_ID),1,4),f4) .
EXECUTE .

Related

Why flang Fortran print adds a new line at a certain width? [duplicate]

I want to write the following output to a txt file using f77:
14 76900.56273 0.000077 -100000 1000000000 -0.769006
I use:
write(6,*) KINC, BM, R2, AF, BK, BM/AF
without any format (which works well in terms of decimal digits). However in my txt file the output is written as:
14 76900.56273 0.000077 -100000
1000000000 -0.769006
Because I think there is a fixed column width limit by default. I don't know if it is possible to change this so that I can just copy and paste it to excel.
I've looked at FORTRAN 77 Language Reference but I haven't found a way to do it. Any ideas? Thanks
use format
or check your compiler's option
if your compiler is one of dec/compaq/intel, read this link.
http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-win/hh_goto.htm#GUID-C6A40AAC-81D8-4DD8-A792-62792B3AC213.htm#GUID-C6A40AAC-81D8-4DD8-A792-62792B3AC213
list directed output (fmt=*) :: 80 column limit default.
"There is a property of list-directed sequential WRITE statements called the right margin. If you do not specify RECL as an OPEN statement specifier or in environmental variable FORT_FMT_RECL, the right margin value defaults to 80. When RECL is specified, the right margin is set to the value of RECL. If the length of a list-directed sequential WRITE exceeds the value of the right margin value, the remaining characters will wrap to the next line. Therefore, writing 100 characters will produce two lines of output, and writing 180 characters will produce three lines of output."
In intel's manual, blue color indicates extensions to the Fortran Standards. These extensions (non-standard features) may or may not be implemented by other compilers that conform to the language standard.
oracle(sun) F77
http://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnbu/index.html#z400074369ac
"Output lines longer than 80 characters are avoided where possible"
With the asterisk as the format, you are using listed-directed IO. This is intended as a convenience. It gives the programmer minimal control, with few restrictions on the compiler and incomplete portability. The compiler is free to determine aspects such as line length. If you want control over line length, switch to using an actual format.
P.S. Why use FORTRAN 77? Fortran 90/95/2003 is easier to use and more powerful. gfortran is an open-source compiler.

SVG Path Data with multiple dots in one value

I had to write my own SVG path parser and discovered that I cannot parse some files like Skull_and_crossbones.svg from Wikipedia.
In the second path's data I found -24.57.56 which is just invalid value and I cannot see how to parse it.
If you look at the spec for the grammar of path data, you will find the following explanation below:
The processing of the BNF must consume as much of a given BNF production as possible, stopping at the point when a character is encountered which no longer satisfies the production... for the string M 0.6.5, the first coordinate of the "moveto" consumes the characters 0.6 and stops upon encountering the second decimal point because the production of a "coordinate" only allows one decimal point. The result is that the first coordinate will be 0.6 and the second coordinate will be .5.
For your example, the production -24.57.56 is equivalent to -24.57, 0.56.
You could also say: Leading zeros before a point, commas and whitespace are always optional. Authors writing path data must only use them to avoid ambiguity and make sure that the length of what you can parse as one number fits their intention.
It is not an invalid value. It is two valid values. The first value is -24.57 and the second value is .56.
The path data grammar does not require there to be spaces between coordinate values. Sometimes they are required, though, if the result would be wrong. For example, 1 0.5 cannot be shortened to 10.5

is trim in delphi can be bypassed?

i am trying to check if a string is empty by doing the following
if trim(somestring) = '' then
begin
//that an empty string
end
i am doing this empty check in my client application , but i notice that some clients inserts empty strings even with this check applied .
on my Linux server side those empty chars showing as squares and when i copy those chars i can be able to bypass the empty string check like the follwing example
‍‍‍
if you copy this empty chars the check will not be effected how can i avoid that ?
Your code is working correctly and the strings are not empty. An empty string is one whose length is zero, it has no characters. You refer to empty characters, but there is no such thing. When. your system displays a small empty square that indicates that the chosen font has no glyph for that character.
Let us assume that these strings are invalid. In that case the real problem you have is that you don't yet fully understand what properties are required for a string to be valid. Your code is written assuming that a string is valid if it contains at least one character with ordinal value greater than 32. Clearly that test is not correct. You need to step back and work out the precise rules for validity. Only when these are clear in your mind can you correct you program and check for validity correctly.
On the other hand perhaps these strings are valid and the mistake is simply that you are erroneously determining otherwise when you inspect the data. Only you can know this, we don't have the information.
A useful technique in all of this is to inspect the ordinal values of the strings. Loop through the characters printing the ordinal value of each one. That allows you to see what is really there and not be at the mercy of non-printing characters, characters with no glyph, invalid encodings, etc.
Since Trim is pretty simple function, it omits only characters with less than or equal dec 32 in ASCII table
( Sample from System.SysUtils.pas )
while S.Chars[L] <= ' ' do Dec(L);
Therefore it's possible that You just can't see some exotic chars ( > ASCII 128) due to bad encoding used with Your input string.
try to use :
StrToInt(Ord(SomeChar))
On every char that is not "trimmed" and remove them by hand or check Your encoding.
Kind Regards

Informix 4GL report to screen - Reverse

I have a generated report in Informix 4GL that prints to the screen.
I need to have one column displayed in reverse format.
I tried the following:
print line_image attribute(reverse)
But that doesn't work. Is this possible at all?
Adding on to the previous answer, you can try the following
print "\033[7mHello \033[0mWorld"
\033[7m means to print in reverse. And, \033[0m means to go back to standard.
If you mean "is there any way at all to do it", the answer's "yes". If you mean "is there a nice easy built-in way to do it", the answer's "no".
What you'll need to do is:
Determine the character sequence that switches to 'reverse' video — store the characters in a string variable brv (begin reverse video; choose your own name if you don't like mine).
Determine the character sequence that switches to 'normal' video — store the characters in a string variable erv (end reverse video).
Arrange for your printing to use:
PRINT COLUMN 1, first_lot_of_data,
COLUMN 37, brv, reverse_data,
COLUMN 52, erv,
COLUMN 56, next_lot_of_data
There'll probably be 3 or 4 characters needed to switch. Those characters will be counted by the column-counting code in the report.
Different terminal types will have different sequences. These days, the chances are your not dealing with the huge variety of actual green-screen terminals that were prevalent in the mid-80s, so you may be able to hardwire your findings for the brv and erv strings. OTOH, you may have to do some fancy footwork to find the correct sequences for different terminals at runtime. Shout if you need more information on this.
A simple way which might allow you to discover the relevant sequences is to run a program such as (this hasn't been anywhere near an I4GL compiler — there are probably syntax errors in it):
MAIN
DISPLAY "HI" AT 1,1
DISPLAY "REVERSE" AT 1,4 ATTRIBUTE(REVERSE)
DISPLAY "LO" AT 1, 12
SLEEP 2
END MAIN
Compile that into terminfo.4ge and run:
./terminfo.4ge # So you know what the screen looks like
./terminfo.4ge > out.file
There's a chance that won't use the display attributes. You'd see that if you run cat out.file and don't see the reverse flash up, then we have to work harder.
You could also look at the terminal entry in the termcap file or from the terminfo entry. Use infocmp $TERM (with the correct terminal type set in the environment variable) and look for the smso (enter standout mode) and rmso (exit standout mode) capabilities. Decipher those (I have rmso=\E[27m and smso=\E[7m for an xterm-256color terminal; the \E is ASCII ESC or \033) and use them in the brv and erv strings. Note that rmso is 5 characters long.

LC3 Stack Implementation

I have a problem I'm trying to figure out:
Write an LC-3 assembly language program that asks the user to input a string (the end of the input string is the enter key), and prints the words of this string in reverse order. For example, if the input string is “Hello, my name is Joe”, the output of your program should be “Joe is name my Hello,” Test your program with LC-3 simulator. Your code must be well documented. Hint: Consider using stack for easier implementation.
I know how I would be able to use a stack to return something exactly reversed ex: input "AB CD EF" output "FE DC BA"
but how would I be able to only reverse the order of segments?
ex: input "AB CD EF" output "EF CD AB"
Thanks
The best thing to do would be increase the number of blocks of memory that get pushed onto your stack at one time. For example, if you are only expecting the user to enter in words that are equal to or less than 5 characters, then one "push" on your stack would take up 5 blocks of memory.
This would make it so you could "pop" the words off the stack without having to rearrange the order of each of the letters.

Resources