WHILE IMPOSING sanctions on America's allies for helping Moscow build a natural gas pipeline, President Reagan has justified the sale of U.S. grain to the Soviets on the grounds that such sales "will result in the Soviet Union having to pay out hard cash, and they're not too flush with that right now."

"The pipeline," the president has stated, "will result in the Soviet Union getting hard cash . . . which it can then use to further build up its military might."

In fact, it is by buying grain from the United States that the Soviet Union saves vast sums -- far more than it spends on the grain itself. In other words, U.S. grain sales make it easier, not harder, for the Soviets to meet other requirements, including their military buildup.

Indeed, the Soviets are saving roughly $32 billion this year by selling oil for grain rather than producing their own grain.

The key here is a concept economists call comparative advantage -- or disadvantage. For the Soviets, there is a huge comparative disadvantage to producing grain.

Because Soviet agriculture is so inefficient, the U.S.S.R. needs much more capital investment, labor and raw materials to expand grain harvests than it takes to produce other goods, which can then be sold in the West to raise the money to buy grain instead of growing it.

At the same time, the Soviets have an enormous comparative advantage in the production of oil and gas, products they can sell in the capitalist world. Relatively speaking, the Russians can get much more rumble for the ruble by producing gas or oil and using the proceeds to buy grain than they can by trying to produce more grain of their own.

The availability of grain imports enables the Soviets to eliminate costly expenditures on fertilizer, agricultural machinery, grain drying facilities, storage facilities, etc. In addition, it permits the Soviet political leadership to avoid undertaking major institutional and incentive reforms in the agricultural sector -- reforms that inevitably would have political repercussions.

The Reagan view that Soviet purchases of grain represent a drain on the economy assumes that the Soviet Union has a fixed amount of hard currency for purchasing goods from the West -- that is, every dollar the Soviets spend on grain is a dollar they can't spend on anything else. But this is incorrect.

If the Soviet Union is a relativity low-cost producer of oil, gas and other raw materials and a relatively high-cost producer of grain, then the Soviets should want to export petroleum products and import grain.

The degree to which such a course would pay off can be shown by comparing the tradeoff between the relative costs of producing and buying grain and other commodities important in Soviet trade. Petroleum products give us the best examples for this comparison because they provide the bulk of Soviet hard-currency earnings.

Look, first, at what has happened to the terms of trade between crude oil and grain on the world market over the past decade. In 1970, one metric ton of oil sold by the Soviets purchased barely 200 kilograms of wheat. By 1981 the same ton of oil bought eight times as much wheat.

Now look at the costs of producing grain or oil and gas inside the Soviet Union. These figures cannot be precise, because it is extremely difficult to obtain meaningful prices for goods and services traded in the centrally planned Soviet economy. At Wharton Econometrics we have tried to use the best figures available to estimate the relative domestic production costs for oil, gas and grain. We did this by estimating the cost of capital investment, equipment, labor and other elements needed to expand production of these commodities.

In 1970, we estimate, whereas a ton of oil cost as much as 200 kilograms of wheat on the world market, the Soviets could produce an additional ton of oil for the same cost that they could grow 60 to 100 kilograms of wheat. By the early 1980s the situation had gotten even worse for the Russians. In 1981, one ton of oil would purchase nearly 1.6 tons of wheat on the world market, but inside the Soviet Union, the additional costs of producing one ton of oil would -- if applied to grain production -- only provide 200 to 250 kilograms of grain.

In other words, in 1970 it was two to three times less efficient for the Soviets to invest in wheat production than in oil production, when measured by the standard of world market prices. But in the early 1980s it has become six to eight times less efficient for the Soviets to invest in grain production. No wonder they prefer to buy U.S. grain surpluses while maximizing their oil and gas production. (By our calculations, gas is even more profitable for the Russians than oil.)

The Soviet Union is expected to import about 46 million metric tons of grain this year at a cost equivalent to the world-market price of of 29.2 million metric tons of crude oil (assuming, for simplicity, that all grain is priced as wheat). If the Soviets tried to grow those 46 million tons of grain at home, the domestic cost of such increased production would be equivalent to the cost of producing about 159 million metric tons of oil.

Thus by importing grain instead of producing it, the Soviet Union saves resources equivalent to about 130 million metric tons of oil, which would be valued at close to $32 billion on the world market. That $32 billion represents a very rough estimate of what the Soviets save this year by trading oil for grain instead of growing all their own grain.

(We are assuming, of course, that the Soviets have an unlimited capacity to expand grain production if they decide to invest enough resources to do so. This is by no means certain, but our basic findings about the comparative advantage to the Soviets of importing grain remain valid.)

So, by spending about $7 billion to import 46 million tons of grain this year, the Soviets are actually saving roughly $32 billion, and they are escaping the need to make dramatic domestic reforms as well. This seems like a good deal for the Russians.