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

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

7 REPLIES 7
novinosrin
Tourmaline | Level 20

can you post a sample of your data? plz 

Just helps testing

Mogreenly
Calcite | Level 5

Hi novinosrin,

 

Thanks for your reply.

 

Here is a sample of the two variables in question.

 

novinosrin
Tourmaline | Level 20

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

Mogreenly
Calcite | Level 5

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.

novinosrin
Tourmaline | Level 20

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 🙂 Have fun!

Kurt_Bremser
Super User

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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