One thought, if the sole purpose of the second data step is to get a count of the unique variables it has one problem in that the data should be sorted by the variable you are trying to count.
Another approach would be to use some thing like:
Proc freq data=INPUT1 order=freq;
table mname /nopercent missing;
run;
Your example actually didn't have spaces but were null strings (empty).
From the online help for input statement, column:
Both leading and trailing blanks within the field are ignored. Therefore, if numeric values contain blanks that represent zeros or if you want to retain leading and trailing blanks in character values, read the value with an informat. See INPUT Statement, Formatted.
Missing Values
Missing data do not require a place-holder. The INPUT statement interprets a blank field as missing and reads other values correctly. If a numeric or character field contains a single period, the variable value is set to missing.
... View more