01-13-2018 12:01 AM - edited 01-13-2018 12:02 AM
I am facing a problem in Proc format. I was trying to convert a character variable to numeric variable by using the input function and at the same time i am applying a user defined character format to that character variable. but it is showing a warning in the log window.
WARNING: The data set WORK.BB may be incomplete. When this step was stopped there were 0 observations and 2 variables.
WARNING: Data set WORK.BB was not replaced because this step was stopped.
The program I submitted is as follows:
'abc' = 1
'bbc' = 2
'ccc' = 3;
input name $;
But if i use Put function in place of input function it is working fine with out any warning. But Put function usually converts Numeric to Character. But why is it working for a character variable?
If i use this program then it is working fine again.
Can some one please Clarify this?
Thanks in Advance.
01-14-2018 04:00 PM
Thank you for your reply.
Actually it is working with out any errors with or with out $ sign.
Both of these result in the same output.
But my question was when we are converting a character variable to Numeric we need to use input function. and in this program i am trying to convert a character variable to numeric , (in addition i need to apply a user defined format) But if i use INPUT function it throws an error. but if i use PUT function it is fine(with or without $ sign). So why we are unable to convert character variable to numeric by applying a format using INPUT variable?
01-13-2018 02:44 AM
if you want to use a format in an input statement, you have to create an informat:
proc format; invalue $namefmt 'abc' = 1 'bbc' = 2 'ccc' = 3
01-14-2018 04:30 PM
Thank you so much for your reply.
I know this might be very small thing you, But i was not understanding the logic behind it.
1. Using an input function will convert a character variable to numeric.
2. But if i use the input function for the below program it is not converting the character value to numeric. it is just applying the format.
proc format; invalue $namefmt 'abc' = 1 'bbc' = 2 'ccc' = 3; run;
as you advised i have created an informat and applied in this way.
Yes ! now i get the output. A new variable Newname(Character variable) is created and it contains the data 1 2 and 3. but my question is Why is it a character variable? when i use a input function it should convert to numeric but why is it not converting to numeric?
The same is happening with the Put function. When I use a put function it is applying the format. In general PUT function converts numeric values to character. But here if i use a put function for a character variable it is working fine without any errors.The resultant new variable is a character again.
Both of these programs are producing the same output.
01-15-2018 01:37 AM
If you want to have a numeric value, you have to create a numeric informat, so omit the $'s:
data old; name = 'abc'; run; proc format; invalue namefmt 'abc' = 1 'bbc' = 2 'ccc' = 3 ; run; data new1; set old; newname=input(name,namefmt.); run;
01-16-2018 02:31 PM
Although not immediately obvious (and a continuing source of confusion) there is a difference between INFORMATs (used by the INPUT statement and the INPUT function) and FORMATs (used by the PUT statement and the PUT function). The INVALUE statement in PROC FORMAT creates INFORMATs and you will notice from the previous post by @KurtBremser that the type of the INFORMAT depends on the result (numeric INFORMATS yield a numeric result). FORMATS created by the VALUE statement are numeric if the incoming value is numeric.