Desktop productivity for business analysts and programmers

Converting numeric to character

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Converting numeric to character

Hi,

 

I am trying to use the PUT function to convert a variable in z8 numeric format to a character format.

 

My code is as follows:

 

char_id = put(id,z8.);

 

where id is a numeric variable of format z8

 

However, when I run this the char_id variable is created, but is empty for every observations.

 

Thanks,

Mark


Accepted Solutions
Solution
Tuesday
Super User
Posts: 2,040

Re: Converting numeric to character

Posted in reply to Mogreenly

I don't see any problem in the code or the result.

 

Here is my test:

 

589 data w1;
590 set tmp1.sample;
591 char_id = put(id,z8.);
592 put char_id=;
593 run;

char_id=00244302
char_id=01913948
char_id=01913956
char_id=01913964
char_id=01981501
char_id=02099179
char_id=02099187
char_id=02219492
char_id=02230694
char_id=02233014
char_id=02237317
char_id=02237319
char_id=02237320
char_id=02240835
char_id=02240836
char_id=02240837
char_id=02241751
char_id=02241927

View solution in original post


All Replies
Super User
Posts: 2,040

Re: Converting numeric to character

Posted in reply to Mogreenly

can you post a sample of your data? plz 

Just helps testing

New Contributor
Posts: 3

Re: Converting numeric to character

Posted in reply to novinosrin

Hi novinosrin,

 

Thanks for your reply.

 

Here is a sample of the two variables in question.

 

Attachment
Solution
Tuesday
Super User
Posts: 2,040

Re: Converting numeric to character

Posted in reply to Mogreenly

I don't see any problem in the code or the result.

 

Here is my test:

 

589 data w1;
590 set tmp1.sample;
591 char_id = put(id,z8.);
592 put char_id=;
593 run;

char_id=00244302
char_id=01913948
char_id=01913956
char_id=01913964
char_id=01981501
char_id=02099179
char_id=02099187
char_id=02219492
char_id=02230694
char_id=02233014
char_id=02237317
char_id=02237319
char_id=02237320
char_id=02240835
char_id=02240836
char_id=02240837
char_id=02241751
char_id=02241927

New Contributor
Posts: 3

Re: Converting numeric to character

Posted in reply to novinosrin

Thanks for your help.

 

I tried pulling that section of code out into a separate data step and it seems to be working now. It still does not work when imbedded within another data step (as I was doing before). I suppose there is an underlying nuance of SAS that I do not quite grasp.

Super User
Posts: 2,040

Re: Converting numeric to character

Posted in reply to Mogreenly

Should you further require any help at all, feel free to open a new thread or a follow up question, however you please. 

Welcome to the SAS forum Smiley Happy Have fun!

Super User
Posts: 10,529

Re: Converting numeric to character

Posted in reply to Mogreenly

@Mogreenly wrote:

Thanks for your help.

 

I tried pulling that section of code out into a separate data step and it seems to be working now. It still does not work when imbedded within another data step (as I was doing before). I suppose there is an underlying nuance of SAS that I do not quite grasp.


This means that in your other code you do something that clears either id or your newly created character variable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 10,529

Re: Converting numeric to character

Posted in reply to Mogreenly

Maxim 2: read the log.

See my footnotes for hints on posting data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 113 views
  • 0 likes
  • 3 in conversation