• use of

    From malika elkadali@21:1/5 to All on Sun Sep 5 10:50:28 2021
    Hi all,
    i want to execute this in python but it doesn't work ; i dont' know how can i call the code bethween DEFINE and !ENDDEFINE.
    DEFINE HOTDECK (y = !charend ('/')/deck = !charend ("/")).
    Output New name = hotdeckextra.
    !do !s !in (!y).
    compute randnum = uniform(1).
    sort cases by !deck randnum.
    compute sortclg1 = 1.
    compute sortclg2 = 1.
    compute sortcld1 = 1.
    compute sortcld2 = 1.
    !DO !v !in (!deck).
    create sortd1v = lead(!v,1).
    create sortd2v = lead(!v,2).
    if (lag(!v) <> !v) sortclg1 = 0.
    if (lag(!v,2) <> !v) sortclg2 = 0.
    if (sortd1v <> !v) sortcld1 = 0.
    if (sortd2v <> !v) sortcld2 = 0.
    !DOEND.
    !let !newname = !CONCAT (!s, HD).
    compute newvar = !s.
    apply dictionary from * /source variables = !s /target variables = newvar. execute.
    Create yLead = Lead(!s,1).
    Create yLead2 = Lead (!s,2).
    DO If (Missing(newvar)).
    + DO IF ((sortclg1 = 1) AND Not Missing(lag(!s))).
    + Compute newvar = Lag(!s).
    + ELSE IF ((sortcld1 = 1) AND Not Missing (yLead)).
    + Compute newvar = yLead.
    + ELSE IF ((sortclg2 = 1) AND Not Missing(Lag(!s,2))).
    + Compute newvar = Lag(!s,2).
    + ELSE IF ((sortcld2 = 1) AND Not Missing(yLead2)).
    + Compute newvar = yLead2.
    + END IF.
    End If.
    Match Files/File = */drop yLead ylead2 sortd1v sortd2v sortclg1 sortclg2 sortcld1 sortcld2 randnum.
    execute.
    rename variables (newvar = !newname).
    !doend.
    output close name = hotdeckextra.
    !ENDDEFINE.


    GET FILE = 'D:\app\test.sav'.
    HOTDECK y=SALAIRE / deck=AGE.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Weaver@21:1/5 to malika elkadali on Tue Sep 7 08:26:14 2021
    The macro definition shows that you need to use a slash after the deck variable(s) too. Try this:

    HOTDECK y=SALAIRE / deck=AGE /.



    On Sunday, September 5, 2021 at 1:50:30 PM UTC-4, malika elkadali wrote:
    Hi all,
    i want to execute this in python but it doesn't work ; i dont' know how can i call the code bethween DEFINE and !ENDDEFINE.
    DEFINE HOTDECK (y = !charend ('/')/deck = !charend ("/")).
    Output New name = hotdeckextra.
    !do !s !in (!y).
    compute randnum = uniform(1).
    sort cases by !deck randnum.
    compute sortclg1 = 1.
    compute sortclg2 = 1.
    compute sortcld1 = 1.
    compute sortcld2 = 1.
    !DO !v !in (!deck).
    create sortd1v = lead(!v,1).
    create sortd2v = lead(!v,2).
    if (lag(!v) <> !v) sortclg1 = 0.
    if (lag(!v,2) <> !v) sortclg2 = 0.
    if (sortd1v <> !v) sortcld1 = 0.
    if (sortd2v <> !v) sortcld2 = 0.
    !DOEND.
    !let !newname = !CONCAT (!s, HD).
    compute newvar = !s.
    apply dictionary from * /source variables = !s /target variables = newvar. execute.
    Create yLead = Lead(!s,1).
    Create yLead2 = Lead (!s,2).
    DO If (Missing(newvar)).
    + DO IF ((sortclg1 = 1) AND Not Missing(lag(!s))).
    + Compute newvar = Lag(!s).
    + ELSE IF ((sortcld1 = 1) AND Not Missing (yLead)).
    + Compute newvar = yLead.
    + ELSE IF ((sortclg2 = 1) AND Not Missing(Lag(!s,2))).
    + Compute newvar = Lag(!s,2).
    + ELSE IF ((sortcld2 = 1) AND Not Missing(yLead2)).
    + Compute newvar = yLead2.
    + END IF.
    End If.
    Match Files/File = */drop yLead ylead2 sortd1v sortd2v sortclg1 sortclg2 sortcld1 sortcld2 randnum.
    execute.
    rename variables (newvar = !newname).
    !doend.
    output close name = hotdeckextra.
    !ENDDEFINE.


    GET FILE = 'D:\app\test.sav'.
    HOTDECK y=SALAIRE / deck=AGE.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)