- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
please could you help me to understand this because my head is gonna exploted.
I create the next have dataset:
data have;
input pulse $ pulsen;
datalines;
80.0 80.0
90.0 90.0
.
;
data want;
lenght pulsechar pulsechar2 $20.;
set have;
pulsechar=strip(input(pulsen,best.)); convert a numeric variable to character variable;
pulsechar2=pulse;
run;
The issue i have is:
even SAS show me pulsechar as a character variable,
the missing value numeric .
is not converted to a blank value, the dot is remaining there,
and i found it very annoying, because pulsechar is not a real character value.
Is that conversion numeric to character pulsechar=strip(input(pulsen,best.)); no strictly speaking
a real conversion from numeric to character?
Any help to make pulsechar (show the blank value as a dot) exactly the same than pulsechar2 (show the blank value)?
Thank you in advance.
Cuan.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think you are looking for the MISSING option.
Here is some test code that shows two ways to convert a number into a character string.
data test;
input num ;
char1 = put(num,best12.);
char2 = cats(num);
cards;
1
-1
.
1.5
;
So that results in this output:
Obs num char1 char2 1 1.0 1 1 2 -1.0 -1 -1 3 . . . 4 1.5 1.5 1.5
But if you first change the MISSING option to a space instead of period:
options missing=' ';
And then run the same code you get this instead:
Obs num char1 char2 1 1.0 1 1 2 -1.0 -1 -1 3 4 1.5 1.5 1.5
It is not clear to me where you think your code is converting numbers to characters. The only EXPLICIT conversion you have is an INPUT() function, which must read from a character variable so is obviously not for converting numbers into anything. Plus it is a little strange to use BEST as an informat, but SAS is forgiving and will treat BEST as an alias for the normal numeric informat. The idea of the BEST format is to find the best way to represent the given number as a string of the specified length. That concept doesn't really translate to informats. There isn't any best way to represent a number as a number, there is only one way to represent any number as a number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if pulsen > . then pulsechar=strip(put(pulsen,best.));
now you get the blank value in the pulsechar charcater variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think you are looking for the MISSING option.
Here is some test code that shows two ways to convert a number into a character string.
data test;
input num ;
char1 = put(num,best12.);
char2 = cats(num);
cards;
1
-1
.
1.5
;
So that results in this output:
Obs num char1 char2 1 1.0 1 1 2 -1.0 -1 -1 3 . . . 4 1.5 1.5 1.5
But if you first change the MISSING option to a space instead of period:
options missing=' ';
And then run the same code you get this instead:
Obs num char1 char2 1 1.0 1 1 2 -1.0 -1 -1 3 4 1.5 1.5 1.5
It is not clear to me where you think your code is converting numbers to characters. The only EXPLICIT conversion you have is an INPUT() function, which must read from a character variable so is obviously not for converting numbers into anything. Plus it is a little strange to use BEST as an informat, but SAS is forgiving and will treat BEST as an alias for the normal numeric informat. The idea of the BEST format is to find the best way to represent the given number as a string of the specified length. That concept doesn't really translate to informats. There isn't any best way to represent a number as a number, there is only one way to represent any number as a number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content