Hi I have a problem converting numeric to character using put statement . It doesn't gets converted and displays error. can u pls tell me what format to use to convert numeric to character and also give the list of all formats and informants
If you want help with the proper syntax, you will need to show the log from what you have tried.
Here is an example of the most common error when converting from numeric to character:
data want;
set have;
var = put(var, z5.);
run;
The PUT function really works .... it converts the value of VAR to a character string. However, you can't store the character string in VAR, since VAR is already defined as numeric. The PUT function cannot change an existing variable from being numeric to being character. Instead, you need to create a new variable:
newvar = put(var, z5.);
That may or may not be your error, but it is a very common error.
As for a list of all formats and informats ... there are hundreds of them. You will have to search the documentation for those, although this is a decent starting point:
You won't need to know about informats, since they don't convert from numeric (only from character).
If you want help with the proper syntax, you will need to show the log from what you have tried.
Here is an example of the most common error when converting from numeric to character:
data want;
set have;
var = put(var, z5.);
run;
The PUT function really works .... it converts the value of VAR to a character string. However, you can't store the character string in VAR, since VAR is already defined as numeric. The PUT function cannot change an existing variable from being numeric to being character. Instead, you need to create a new variable:
newvar = put(var, z5.);
That may or may not be your error, but it is a very common error.
As for a list of all formats and informats ... there are hundreds of them. You will have to search the documentation for those, although this is a decent starting point:
You won't need to know about informats, since they don't convert from numeric (only from character).
In addition to what Astounding said, formats do not convert variables from numeric to character. Formats DISPLAY (not convert) numeric variables as character. Applying a format to a numeric variable means that the variable remains numeric, but may be displayed as a set of characters.
As @Astounding points out, the PUT statement can create a new variable with a new name which is a different type.
can we use the converted variable as character in further statements
Your LENGTH statement is defining the new variables as numeric, when you need them to be character. Try it this way:
length sbp_chk dbp_chk $4;
Thanks
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 16. 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.