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
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
can you post a sample of your data? plz
Just helps testing
Hi novinosrin,
Thanks for your reply.
Here is a sample of the two variables in question.
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
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.
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!
@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.
Maxim 2: read the log.
See my footnotes for hints on posting data.
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!
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.
Ready to level-up your skills? Choose your own adventure.