Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

Hello! Can you please help with writing a script to dummy code uncoded arguments into missing = "." ? In one of my variables, I have arguments that I've already coded and some arguments are left blank. Those that are uncoded, I'd like to code as missing ("."). But, rather than doing so by hand, I'd like to do it with a script. Please help. Thank you.

asked 31 Jul '13, 11:43

LanaKarasik's gravatar image

LanaKarasik
81111115
accept rate: 0%


Uncoded arguments are just an empty string (so, nothing between the quotes, just ""). To find all the uncoded arguments and change them to be just a period (or to change them to anything else), do this:

begin
# Get variable we're going to work with
var = getVariable("variablename")

# Loop over each cell and find only arguments that weren't coded
for varcell in var.cells
    if varcell.arg == ""
        # Change the uncoded arguments to a be a period
        varcell.change_arg("arg", ".")
    end
end

# Set the variable back to the spreadsheet
setVariable("variablename",var)

end

Note that you can also make a script like this loop over multiple files. We've posted examples of scripts that loop over files elsewhere on the forum, so you can look at those. Since you're making a change to the spreadsheet, if you want to loop over files you'll need one additional line after you set the variable to save the changes to the spreadsheet/database.

save_db(filedir + file)

You'll have to replace "filedir" and "file" to match whatever you called the file directory and the filenames in the code at the top that sets up to loop over files of course. If looping over files is something you want to do and you can't make it work, just post another question and we can help with that part. If you don't need to loop over multiple files you don't need to worry about save_db at all.

permanent link

answered 31 Jul '13, 16:43

WhitneyCole's gravatar image

WhitneyCole ♦
417239
accept rate: 21%

You have it almost right. You actually want to keep the function you're using as "change_arg" and not replace 'arg' with the variable name. change_arg is the name of the function itself.

begin 
locsleepfeedelim = getVariable("locsleepfeedelim")

    #Loop over each cell and find only arguments that weren't coded for varcell in var.cell
    for locsleepfeedelimcell in locsleepfeedelim.cells
      if locsleepfeedelimcell.timelim_typelim == ""
        #Change the uncoded arguments to be a period
        locsleepfeedelimcell.change_arg("timelim_typelim",".")
    end
end

#Set the variable back to the spreadsheet
setVariable("locsleepfeedelim", locsleepfeedelim)
end
permanent link

answered 09 Aug '13, 21:24

KCSoska's gravatar image

KCSoska ♦
2363
accept rate: 17%

edited 09 Aug '13, 21:25

Hi, I still can't quite get this to work. In the above script, I've changed var, variable name, varcell, var.cells, with the actual variable name. But, does the "arg" in the above script also need to be modified with the actual argument name that I am trying to recoding into "." ? I did, but still in the file the argument remains uncoded. Heres' my modified script:

locsleepfeedelim is the variable (column) name timelim_typelim is the name of the argument within the variable (column) locsleepfeedelim

begin
locsleepfeedelim = getVariable("locsleepfeedelim")

    #Loop over each cell and find only arguments that weren't coded for varcell in var.cell
    for locsleepfeedelimcell in locsleepfeedelim.cells
      if locsleepfeedelimcell.timelim_typelim == ""
        #Change the uncoded arguments to be a period
        locsleepfeedelimcell.change_timelim_typelim("timelim_typelim",".")
    end
end

#Set the variable back to the spreadsheet
setVariable("locsleepfeedelim", locsleepfeedelim)

end

permanent link

answered 09 Aug '13, 19:29

LanaKarasik's gravatar image

LanaKarasik
81111115
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×46
×6
×1

question asked: 31 Jul '13, 11:43

question was seen: 3,982 times

last updated: 09 Aug '13, 21:25

powered by OSQA