4

I'm trying to use INPUT function, as it is always suggested, but it seems that SAS has some problems with proper interpretation of amounts like: 2,30 1,61 0,00 ...and I end up with missing values. Perhaps it's caused by comma being thousands separator where SAS come from ;)

data temp;
    old = '1,61';
    new = input(old, 5.2);
run;

Why the result of above is new = .?

It seems that I've found some work-around - by replacing comma with a period using TRANWRD before INPUT function is called (vide code below), but it's quite ugly solution and I suppose there must be a proper one.

data temp;
    old = '1,61';
    new = input(tranwrd(old,',','.'), 5.2);
run;

1 Answer 1

5

The reason new = . in your example is because SAS does not recognize the comma as a decimal separator. See the note in the log.

NOTE: Invalid argument to function INPUT at line 4 column 11. old=1,61 new=. ERROR=1 N=1 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.

The documentation contains a list of various SAS informats. Based on the documentation it looks like you can use the COMMAX informat.

COMMAXw.d - Writes numeric values with a period that separates every three digits and a comma that separates the decimal fraction.

The modified code looks like this:

data temp;
    old = '1,61';
    new = input(old,commax5.);
run;

proc print;

The resulting output is:

Obs    old      new

 1     1,61    1.61

If you want to keep the new variable in the same format you can just add the statement format new commax5.; to the data step.

Thanks to Tom for pointing out that SAS uses informats in the INPUT() function.

Sign up to request clarification or add additional context in comments.

1 Comment

The INPUT() function uses INFORMATs, not FORMATs. Fortunately there is an informat named COMMAX that your code will use. However you do NOT want to use the decimal specification on an informat. input(old,commax5.2) would convert '123' into 1.23 since it will put assume that your input string had removed the decimal separator to save space. So just use input(old,commax5.).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.