This JustCode mrs script reads in data from a ddf file and produces a txt file that matches this requirement,
Question Q1 has 15 categories. But when i export thorugh MDM2Quantum, my category data has splited to 2 columns. Lets say categories 1 to 10 in column 101 and categories 11 to 15 in column 102.
But what i need is all my 15 categories should be in columns 101 and 102
i.e., category 1 should have data as “01” in columns 101 and 102
category 2 should have data as “02” in columns 101 and 102
category 3 should have data as “03” in columns 101 and 102
category 4 should have data as “04” in columns 101 and 102
……
category 15 should have data as “15” in columns 101 and 102.
This is the mrs script
Dim oMDM, oVar,iWidth,sLine
Dim iVariableCount,iRowCount
Dim sSQL,oConnection,oRecordset
Dim sPath,iFields,iDataRows
sPath = "D:\DATA\SD\Library\PADCSV\"
' Create the MDM object
Set oMDM = CreateObject("MDM.Document")
oMDM.Open(sPath + "ref.mdd", , 1)
iFields = oMDM.Variables.Count
iVariableCount = 0
iRowCount = 0
Dim oArray[99][9999]
For Each oVar in oMDM.Variables
if ( oVar.IsSystem = False ) then
debug.Log("Question Name : " + oVar.FullName)
' Start code to check if the field has data in it.
Set oConnection = CreateObject("ADODB.Connection")
oConnection.ConnectionString = "Provider=mrOleDB.Provider.2;Data Source=mrDataFileDsc;Location=.ref.ddf;Initial Catalog=.ref.mdd;MR Init Category Names=1"
oConnection.Open()
If ( oConnection.State = 1 ) Then
Set oRecordset = CreateObject("ADODB.Recordset")
oRecordset.Open("SELECT " + oVar.FullName + " FROM VDATA" ,oConnection,3,1)
if oVar.FullName = "Serial" Then
iWidth = 10
Else
Select case oVar.DataType
case is = 1 ' Long
iWidth = len(ctext(oVar.MaxValue))
End Select
End If
iRowCount = 0
Do While oRecordset.EOF = false
Select case oVar.DataType
case is = 1 ' Long
oArray[iVariableCount][iRowCount] = PAD(Ctext(oRecordset[ovar.Fullname].value),iWidth,"0")
case is = 3 ' Categorical
oArray[iVariableCount][iRowCount] = replace(replace(replace(Ctext(oRecordset[ovar.Fullname].value),"{",""),"}",""),"_","")
case else
oArray[iVariableCount][iRowCount] = PAD(Ctext(oRecordset[ovar.Fullname].value),iWidth,"0")
End Select
oRecordset.MoveNext()
iRowCount = iRowCount + 1
Loop
End If
oConnection.Close()
Set oConnection = Null
iVariableCount = iVariableCount + 1
end if
Next
iDataRows = iRowCount
oMDM.Close()
' Create the dms file with the select statement in it.
Dim oFSO, oFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(sPath + "ref.txt", True)
iVariableCount = 0
iRowCount = 0
For iRowCount = 0 to iDataRows
sLine = ""
if ( oArray[0][0] <> "" ) Then
For iVariableCount = 0 to iFields
' ADDED "-" to check spacing allocation
sLine = sLine + oArray[iVariableCount][iRowCount] + "-"
Next
oFile.WriteLine(sLine)
End If
Next
oFile.Close()
Set oFSO = Null
Function PAD(sString,iSize,sWith)
Dim iPos,sPad
For iPos = 1 To iSize
sPad = sPad + sWith
Next
PAD = right(sPad + sString,iSize)
End Function
This is the mdd metadata ( note the category names )
Metadata(en-US, Question, Label, SystemVariables = false)
Serial "Serial"
long;
resp_id "Respondent ID"
long [0 .. 99999];
Tc1 "T1"
categorical [1..]
{
_1 "1 Extrêmement satisfait",
_2 "2 Très satisfait",
_3 "3 Satisfait",
_4 "4 Moyennement satisfait",
_5 "5 Pas du tout satisfait"
};
Tc2 "T2 "
long [0 .. 10];
tc3 "T3"
categorical [1..1]
{
_1 "1 Très certainement",
_2 "2 Certainement",
_3 "3 Probablement",
_4 "4 Probablement pas",
_5 "5 Certainement pas"
};
tc4 "T4"
categorical [1..1]
{
_1 "1 Un très grand avantage",
_2 "2 Un grand avantage",
_3 "3 Un avantage sans plus",
_4 "4 Plutôt un faible avantage",
_5 "5 Aucun avantage du tout"
};
fxcible "Cible"
categorical [1..1]
{
_01 "Clients Bbox",
_02 "Clients Ideo",
_99 "Clients Orange"
};
End Metadata
This is the routing
Routing(Web)
Serial.Ask()
resp_id.Ask()
Tc1.Ask()
Tc2.Ask()
tc3.Ask()
tc4.Ask()
fxcible.Ask()
End Routing
Like this:
Like Loading...