Hi there!
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:
proc format;
value $namefmt
'abc' = 1
'bbc' = 2
'ccc' = 3;
run;
data old;
input name $;
cards;
abc
bbc
ccc
;
run;
data new;
set old;
newname=input(name,namefmt.);
run;
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?
data bb;
set ab;
newname=put(name,namefmt.);
run;
If i use this program then it is working fine again.
data bb;
set ab;
newname=input(put(name,namefmt.),best.);
run;
Can some one please Clarify this?
Thanks in Advance.
try this for the new dataset
data new;
set old;
newname=name;
format newname $namefmt.;
run;
how about apply the $ before the format name.
data bb;
set old;
newname=put(name,$namefmt.);
run;
Hello VDD,
Thank you for your reply.
Actually it is working with out any errors with or with out $ sign.
--------------------------------------------------------------------------------
data bb;
set old;
newname=put(name,namefmt.);
run;
data bb;
-------------------------------------------------
set old;
newname=put(name,$namefmt.);
run;
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?
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
;
run;
Hello KurtBremser,
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.
data new1;
set old;
newname=input(name,$namefmt.);
run;
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.
data bb;
set old;
newname=put(name,$namefmt.);
run;
Both of these programs are producing the same output.
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;
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 @Kurt_Bremser 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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.