SPSS : syntax error involving RECODE command - statistics

I have run the following command in SPSS. But It's showing error
STRING NSAL(A8).
IF(EDU>12 AND GENDER='M') RECODE SAL (0 THRU 75000='A') (75001 THRU HI='B') INTO NSAL.
EXECUTE.
Where have I done mistake?

You can not use IF and RECODE together in one command. Try DO IF instead.
STRING NSAL (A8).
DO IF (EDU>12 AND GENDER='M').
RECODE SAL (0 THRU 75000='A') (75001 THRU HI='B') INTO NSAL.
END IF.
EXECUTE.

Related

Incomplete statement at end of file

After running below command :
sh cqlsh --request-timeout=3600 -f test.cql
I am getting below error :
Incomplete statement at end of file
Even when my first line is use sample; followed by 50 insert queries.
What could be the reasons for this error?
That error is returned if the statement at the end of the file either (a) has invalid syntax, or (b) not terminated correctly.
Sometimes the issue can occur several lines up from the last statement in the input file.
Check that the CQL statements have valid syntax. It might be necessary to do a process of elimination and split the file so there's only 10 statements in each so you can identify the offending statement. Cheers!

Fortran error check on formatted read

In my code I am attempting to read in output files that may or may not have a formatted integer in the first line of the file. To aid backwards compatibility I am attempting to be able to read in both examples as shown below.
head -n 3 infile_new
22
8
98677.966601475651 -35846.869655806520 3523978.2959464169
or
head -n 3 infile_old
8
98677.966601475651 -35846.869655806520 3523978.2959464169
101205.49395364164 -36765.047712555031 3614241.1159234559
The format of the top line of infile_new is '(i5)' and so I can accommodate this in my code with a standard read statement of
read(iunit, '(I5)' ) n
This works fine, but if I attempt to read in infile_old using this, I as expected get an error. I have attempted to get around this by using the following
read(iunit, '(I5)' , iostat=ios, err=110) n
110 if(ios == 0) then
print*, 'error in file, setting n'
naBuffer = na
!rewind(iunit) #not sure whether to rewind or close/open to reset file position
close(iunit)
open (iunit, file=fname, status='unknown')
else
print*, "Something very wrong in particle_inout"
end if
The problem here is that when reading in either the old or new file the code ends up in the error loop. I've not been able to find much documentation on using the read statement in this way, but cannot determine what is going wrong.
My one theory was my use of ios==0 in the if statement, but figured since I shouldn't have an error when reading the new file it shouldn't matter. It would be great to know if anyone knows a way to catch such errors.
From what you've shown us, after the code executes the read statement it executes the statement labelled 110. Then, if there wasn't an error and iostat==0 the true branch of the if construct is executed.
So, if there is an error in the read the code jumps to that statement, if there isn't it walks to the same statement. The code doesn't magically know to not execute the code starting at label 110 if there isn't an error in the read statement. Personally I've never used both iostat and err in the same read statement and here I think it's tripping you up.
Try changing the read statement to
read(iunit, '(I5)' , iostat=ios) n
You'd then need to re-work your if construct a bit, since iostat==0 is not an error condition.
Incidentally, to read a line which is known to contain only one integer I wouldn't use an explicit format, I'd just use
read(iunit, * , iostat=ios) n
and let the run-time worry about how big the integer is and where to find it.

Using Excel to run a statement many times

I am trying to use excel to update a list of part numbers in my database:
UPDATE
stock s
SET
s.STC_AUTO_KEY = 2
WHERE s.WHS_AUTO_KEY = 2 AND
EXISTS(
SELECT
p.PNM_AUTO_KEY
FROM
PARTS_MASTER p
WHERE
s.PNM_AUTO_KEY=p.PNM_AUTO_KEY AND p.PN='102550');
UPDATE
stock s
SET
s.STC_AUTO_KEY = 2
WHERE s.WHS_AUTO_KEY = 2 AND EXISTS(
SELECT
p.PNM_AUTO_KEY
FROM
PARTS_MASTER p
WHERE
s.PNM_AUTO_KEY=p.PNM_AUTO_KEY AND p.PN='204-060-444-003');
The statements run without semicolons, but when I try to run more then one at once and use semicolons I get the error:
SQL Error [911] [22019]: ORA-00911: invalid character
java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
so... it looks like I don't know how run run more then one basic statement at once.
I am using DBeaver to interact with a Oracle database.
Thanks guys, sorry if this a no-brainer.
Try adding a blank line between each update statement if possible. You can do this easily with a text editor that supports regular expressions, just replace ';\n' with ';\n\n'

Extracting string after last instance of delimiter in a Batch file

I'm working on writing a Windows batch file that is called by a Java program. A number of different strings denoting file directories are passed into the batch file as parameters. I am trying to figure out how to extract a string after the last instance of the "\". For example, I have three directories:
C:\Users\owner\Documents
C:\Users\owner\Videos
C:\Users\owner\Pictures\Trip
I would like to split it so that the strings become:
Documents
Videos
Trip
How would you guys suggest I do this?
EDIT: A follow-up question has been asked here: For loop in Windows batch file: Error: "The syntax of the command is incorrect"
After assigned one parameter to "param" variable, use:
for %%a in (%param:\= %) do set lastDir=%%a
This method works as long as the last directory does NOT have spaces. This detail may be fixed, if needed. The processing of all parameters would be like this:
:nextParam
set "param=%~1"
if not defined param goto endParams
for %%a in (%param:\= %) do set lastDir=%%a
echo Last dir: %lastDir%
shift
goto nextParam
:endParams
Or, in a simpler way (with no spaces restrictions):
:nextParam
if "%~1" equ "" goto endParams
echo Last dir: %~N1
shift
goto nextParam
:endParams
If the strings are passed as arguments 1-3. you can use %~n1, %~n2, %~n3 to get the last folder in the path.

Issue with Spaces when Scripting Scala with Process

I am attempting to write an automated script to pngcrush my images (for a website I am working on) and I used scala as a scripting language to write the script to do this. Everything is going well, except that I am having a problem regarding using spaces when I execute the command. I read that you need to use
Seq(a,b,c,d)
where a,b,c,d are strings (that are meant to be separated by a single space) to deal with how Scala/Java handle Strings
The relevant code I have for generating the command to be executed is here. The result variable contains literal path to every filename
for (fileName <- result) {
val string = Seq("pngcrush","brute","-d","\"" + folder.getPath + "/\"","-e",fileName.getName) ++ fileName.getCanonicalPath.replace(" ","\\ ").split(" ").toSeq
I then use
string!
To execute the command. The problem is that the filename for the last section of the command (after the "-e " flag) isn't executed properly because it cannot deal with the directories that have spaces. An example output is shown below
List(pngcrush, brute, -d, "/tmp/d75f7d89-9ed5-4ff9-9181-41ae2fd82da8/", -e, users_off.png, /Users/mdedetrich/3dot/blublocks/src/main/webapp/img/sidebar/my\, group/users_off.png)
And if I run reduceLeft to get the spaces back I obviously get what the proper string is.
pngcrush brute -d "/tmp/1eaca157-0e14-430c-b0a4-677491d70583/" -e users_off.png /Users/mdedetrich/3dot/blublocks/src/main/webapp/img/sidebar/my\ group/users_off.png
Which is what the correct command should be (running the string manually in terminal works fine). However when I attempt to run this through Scala script, I get this
Could not find file: users_off.png
Could not find file: /Users/mdedetrich/3dot/blublocks/src/main/webapp/img/sidebar/my\
Could not find file: group/users_off.png
CPU time decoding 0.000, encoding 0.000, other 0.000, total 0.000 seconds
Any idea what I am doing incorrectly? It seems to be a problem with Scala not parsing strings that have spaces (and splitting it with Seq is not working either). I have tried both using a literal string with spaces and Seq, neither of which seem to work.
Why are you doing this:
replace(" ","\\ ").split(" ")
That is what's splitting the argument, not Process. Why don't you just use the following?
val string = Seq("pngcrush",
"brute",
"-d","\"" + folder.getPath + "/\"",
"-e",fileName.getName,
fileName.getCanonicalPath)

Resources