BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cuan
Obsidian | Level 7

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.

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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. 

 

 

View solution in original post

4 REPLIES 4
cuan
Obsidian | Level 7
sorry pulsechar=strip(put(pulsen,best.)); but still not make the missing value as a blank, the dot still there.
cuan
Obsidian | Level 7
i found this solution in this forum:
if pulsen > . then pulsechar=strip(put(pulsen,best.));

now you get the blank value in the pulsechar charcater variable.
Tom
Super User Tom
Super User

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. 

 

 

cuan
Obsidian | Level 7
thank you very much for your great explanation, sorry i forget , it was a mistake, i mean PUT instead of INPUT.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 6191 views
  • 1 like
  • 2 in conversation