def createvar(ds, name, varlabel, format, measlevel):
    """Create or modify a numeric variable in an open dataset and return index
    
    ds is the dataset object
    name, varlabel, format, and measlevel are the variable properties
    format must be a sequence of type, width, decimals"""
    
    try:
        index = ds.varlist[name].index
        ds.varlist[index].type = 0    # just in case existing variable was a string
    except:
        ds.varlist.append(name, 0)
        index = len(ds.varlist) - 1
    ds.varlist[index].label = varlabel
    ds.varlist[index].format = format
    ds.varlist[index].measurementLevel = measlevel.upper()
    return index