When the optimization process is stable, the results should not be affected by different orders of independent variables in the model. However, when the optimization is not stable, the order of the effects might occasionally make a difference, for example, one model might not even converge while other models might converge successfully. The documentation here https://go.documentation.sas.com/?docsetId=statug&docsetTarget=statug_mixed_details58.htm&docsetVersion=15.1&locale=en#statug_mixed017761 provides some information on how to deal with convergence issues. For example, " Rearranging effects in the MODEL statement so that the most significant ones are first can help, because PROC MIXED sweeps the estimate of X'V-1X in the order of the MODEL effects and the sweep is more stable if larger pivots are dealt with first. If this does not help, specifying starting values with the PARMS statement can place the optimization on a different and possibly more stable path. "
In your case, the two programs have different orders of effects in the CLASS statements, that makes different orders of the design matrix for the interaction effect pstudyid*avisitn, which is essentially the same as specifying the model effects in different orders, so the issues discussed above could appear.
I hope that explains why your first program did not converge while your second program did converge.
What is the error message for your first program?
Jill
... View more