05-28-2014 05:06 AM
I have a dataset where i have few numeric variables and want to convert them into character. I used put function but it is not getting converted to character.
the variable has TYPE: NUM LENGTH: 8 FORMAT: BEST12. INFORMAT: 12.
05-28-2014 05:11 AM
.. a bit rude force, but works ..
05-28-2014 05:33 AM
**If you copy-paste the entire code, hopefully (at least) one of the 3 ways to convert a number to a character variable should work;
Input Number Best12.;
Proc Print Data=S2 NoObs; Run;
05-28-2014 06:15 AM
Whilst the compress and catx might work in certain circumstances, I wouldn't think that is best practice. What you are relying on there is SAS implicitly converting character strings into numeric. If you want to apply any kind of length/formatting etc. it wouldn't work. The two SAS functions put and input are specifically designed to convert num->char and back again. In my example above: strip(put(num,best.)), I have just given best. as I do not know the data in question. However if you are programming it then you should know up front what you want the data to look like. So if I am developing a table with 1 dp percentages I want the output to look like:
54 ( 34.5)
SAS would not implicitly convert as I require (i.e. 3 space before dot), I would need to use: result||" ("||put(pcent,5.2)||")".
Need further help from the community? Please ask a new question.