DATA Step, Macro, Functions and more

Problem While converting Numeric to Character

Accepted Solution Solved
Reply
Super Contributor
Posts: 276
Accepted Solution

Problem While converting Numeric to Character

Hello Everyone.

I am getting little Confused while converting Numeric to Character Format.

I am having Data Like..

Data Test;

input ID Start Date9. End Date9. Amount;

Format Start End Date9.;

datalines;

1 01Jan2012 1Jan2013 5000

1 01Feb2012 1Jan2013 5000

. 01mar2012 1Jan2013 5000

0 01apr2012 1Jan2013 5000

;

run;

Data h;

set test;

x=put(ID,8.);

run;

Above Code Working Perfectly but i am getting confused with 3rd observation in above data.

Normally as per my knowledge Missing Values in Num variables shows As ' . ' and in Char values shows as Blank ' '.

But in above Data Empty value in X(3rd OBs) showing as ' . '

Why this is behaving like this???

Regards.

Sanjeev.K


Accepted Solutions
Solution
‎03-21-2013 12:34 PM
Super User
Posts: 5,096

Re: Problem While converting Numeric to Character

When you have a step you want to perform just some of the time, use an IF THEN statement:

if ID > . then X = put(ID, 8.);

When ID is missing, X will remain blank.

View solution in original post


All Replies
Respected Advisor
Posts: 3,777

Re: Problem While converting Numeric to Character

It shows dot because that is the value you PUT into it with PUT function.

Maybe you need options missing=' ';

Super Contributor
Posts: 276

Re: Problem While converting Numeric to Character

Hi.

Thanks For your reply.

If we use missing= ' ' ,then it works fine for X variable ,but other Numeric Variables also effects.But i want to keep ' . ' in other numeric variables when there is no data.

Regards,

Sanjeev.K

Respected Advisor
Posts: 3,777

Re: Problem While converting Numeric to Character

Missing option does not change the value of numeric variables.   Only the display.  So set it back when you get done.

Solution
‎03-21-2013 12:34 PM
Super User
Posts: 5,096

Re: Problem While converting Numeric to Character

When you have a step you want to perform just some of the time, use an IF THEN statement:

if ID > . then X = put(ID, 8.);

When ID is missing, X will remain blank.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 218 views
  • 3 likes
  • 3 in conversation