malika elkadali
2021-09-05 17:50:28 UTC
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.
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.