
201 N.W.2d 734 (1972)
STATE of Iowa, Appellee,
v.
Roger WIESE, Appellant.
STATE of Iowa, Appellee,
v.
Donald HATCH, Appellant.
Nos. 55456, 55455.
Supreme Court of Iowa.
October 18, 1972.
*736 Dan Johnston, of Jesse, LeTourneau & Johnston, Des Moines, for appellants.
Richard C. Turner, Atty. Gen., Richard N. Winders, Asst. Atty. Gen., and Ronald M. Kayser, County Atty., Marshalltown, for appellee.
Heard before MOORE, C. J., and UHLENHOPP, REYNOLDSON, HARRIS, and McCORMICK, JJ.
McCORMICK, Justice.
These consolidated appeals arise from a resentencing proceeding. Defendants claim they were sentenced under the wrong statute. We agree and reverse and remand for new sentencing.
Defendants were tried and convicted separately for selling marijuana in violation of § 204.2, The Code, 1966. In March 1970 they were each fined $2000 and ordered imprisoned in the state penitentiary "not less than two or more than five years" under § 204.20, The Code, 1966. They took direct appeal but raised no question about their sentences. The cases were affirmed in State v. Wiese, 182 N.W.2d 918 (Iowa 1971). Defendant Wiese then petitioned for postconviction relief alleging in part that his sentence "violated the indeterminate sentence law." Postconviction trial court agreed the sentence was illegal and by order of December 17, 1971, gave the State 30 days to apply for correction of the sentence in the original criminal case. State applications for correction were made in both the Wiese and Hatch cases, and on January 18, 1972, the penitentiary sentences in both cases were changed to "not to exceed two years." No change was made in the fines.
These appeals are bottomed on a contention a new penalty statute became applicable when former Code chapter 204, Uniform Narcotic Drug Act, was repealed by 64 GA, ch. 148, § 605, effective July 1, 1971. Provisions constituting new chapter 204, Uniform Controlled Substances, consisting of §§ 204.101 to 204.602, were enacted by 64 GA, ch. 148 §§ 1-604. Central to these appeals is § 601 of that Act, its savings clause, which relevantly provides:
"Prosecution for any violation of law occurring prior to the effective date of this Act is not affected or abated by the passage of this Act. If the offense being prosecuted is similar to one set out in division IV of this Act then the penalties under division IV shall apply if they are less than those under prior law."
The State concedes everything for applicability of the new penalty except that these cases were "being prosecuted" at the time of resentencing. Defendants seek the benefit of the new penalty only to reduce their fines to $1000 but not to change their prison sentences. As will be shown we do not believe the issues are quite so simple.
I. Jurisdiction of trial court to resentence. No question was raised by the State regarding trial court's jurisdiction to resentence in January 1972. However, jurisdiction of subject matter must derive from law rather than from consent of the parties, and we are required to consider the issue even when not raised in order to avoid unwarranted exercise of judicial authority. City of Clinton v. Owners of Property, etc., 191 N.W.2d 671, 677 (Iowa 1971), and citations; Lynch v. Uhlenhopp, 248 Iowa 68, 80, 78 N.W.2d 491, 498-499 (1956).
Authority for postconviction attack on a sentence which violates a statute of this state is expressly conferred by Code § 663A.2(1). Postconviction courts are *737 charged with entering an appropriate order "with respect to the conviction or sentence in the former proceedings, and any supplementary orders as to * * * correction of sentence." § 663A.7, The Code; see also State v. Mulqueen, 188 N.W.2d 360, 363 (Iowa 1971). Just as in habeas corpus practice, where a sentence is found invalid the matter is properly referred back to the original criminal case for resentencing. Proceedings commence with the stage at which the vitiating defect occurred. Cf. State v. Sefcheck, 261 Iowa 1159, 1165, 157 N.W.2d 128, 131-132 (1968); Birk v. Bennett, 258 Iowa 1016, 1021, 141 N.W.2d 576, 579 (1966), and citations. Procedure in the Wiese case is remarkably analogous to that in Wilson v. Bennett, 252 Iowa 601, 107 N.W.2d 435 (1961). The original criminal cases were the proper forums for entry of new judgments.
Since the former appeals did not adjudicate the legality of the sentences they do not preclude subsequent attack and correction. State v. Thomas, 81 Ariz. 124, 302 P.2d 261 (1956); 24 C.J.S. Criminal Law § 1587 at 589; 24B C.J.S. Criminal Law § 1952(9) at 415-416; see also United States v. Coke, 404 F.2d 836 (2 Cir. 1968); Ng Pui Yu v. United States, 352 F.2d 626 (9 Cir. 1965).
Further, a trial court does not exhaust its jurisdiction until a valid judgment is entered. State v. Shilinsky, 248 Iowa 596, 81 N.W.2d 444 (1957). A sentence not permitted by statute is void. State v. Hopp, 190 N.W.2d 836 (Iowa 1971), and citations. The original prison terms in these cases were therefore void because former Code § 204.20 required sentences to a specific term of years rather than an indeterminate or indefinite term. Masteller v. Board of Control, 251 Iowa 234, 100 N.W.2d 111 (1959).
Trial court had jurisdiction to resentence.
II. Applicability of the new penalty. It is evident from the language of the savings clause in the new statute that the legislature intended to make its penalties applicable to all future sentences where they were less than those in the old statute. Penal statutes are strictly construed. An ameliorative change should be extended to every case in which it properly can apply. In re Estrada, 63 Cal.2d 740, 48 Cal.Rptr. 172, 408 P.2d 948 (1965); State v. Randolph, 186 Neb. 297, 183 N. W.2d 225 (1971); People v. Oliver, 1 N. Y.2d 152, 151 N.Y.S.2d 367, 134 N.E.2d 197 (1956); State v. Pardon, 272 N.C. 72, 157 S.E.2d 698 (1967); Belt v. Turner, 25 Utah 2d 230, 479 P.2d 791 (1971), aff'd on rehearing, 25 Utah 2d 380, 483 P.2d 425 (1971). The new statute could apply in every case involving a similar charge under the statutes in which valid sentence had not been pronounced as of July 1, 1971. "The key date is the date of final judgment." In re Estrada, supra, 48 Cal. Rptr. at 175, 408 P.2d at 951. A case which has not reached valid final judgment is "being prosecuted." See United States v. Gonware, 415 F.2d 82, 84 (9 Cir. 1969); Sigmon v. Commonwealth, 200 Va. 258, 105 S.E.2d 171 (1958); 22 C.J.S. Criminal Law § 1 f at 8. In the present cases, since valid final judgments had not been entered as of the effective date of the new statute, its penalty provisions were applicable.
Defendants are right in their contention trial court erred in resentencing them under the old statute.
III. The remedy. Under the new statute defendants' offenses would be possession with intent to deliver a controlled substance (marijuana), punishable "by imprisonment in the penitentiary for not to exceed five years and by a fine of not more than one thousand dollars." 64 GA, ch. 148, § 401, subd. 1, par. a(2). Accommodation offenses are punishable "by imprisonment in the county jail for not to exceed one year or by a fine of not more than five hundred dollars, or by both such imprisonment and fine." 64 GA, ch. 148, §§ 401, 410. They are content with imprisonment "not to exceed two years" imposed by *738 trial court in the January 1972 resentencing proceeding and complain only of the $2000 fines.
However, there is no way these purported prison terms can be permitted to stand. As indeterminate sentences they were not permissible under the prior statute. Masteller v. Board of Control, supra. Where a statute requires sentence to a term of years and an indeterminate sentence is given, it is too indefinite to be valid. State v. Stevenson, 195 N.W.2d 358, 360 (Iowa 1972), and citations. Thus, even if resentencing under the old statute had been proper the sentences given were fatally defective. Since the former penalty is inapplicable we need not decide whether the fines could have stood as severable. See Fleming v. State, 113 Ga.App. 857, 149 S.E.2d 836 (1966); 24 C.J.S. Criminal Law § 1577 at 531.
The new statute does provide for an indeterminate sentence, but the legislature has established the maximum imprisonment at not to exceed five years. The court has no authority to fix a lesser prison term. Under an indeterminate sentence the parole board determines the minimum time served. State v. Kulish, 260 Iowa 138, 148 N.W.2d 428 (1967). Defendants cannot be resentenced to prison other than with indeterminate five year terms. The prior sentences are void and give defendants no vested right to prevent assessment of penalties authorized by the statute even where they are greater. State v. Taylor, 258 Iowa 94, 137 N.W.2d 688 (1965); State v. Shilinsky, supra.
Defendants have established their right to be resentenced under the new statute. Trial court has a much better vantage point than we do to make the determinations necessary to pronouncement of new sentences, and therefore the cases will be remanded for that purpose. Defendants shall be given credit against any incarceration imposed for any time served under their prior sentences in addition to any credit to which they may be entitled under Code § 246.38. Reversed and remanded for new sentences.
