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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 10999 views
  • 0 likes
  • 3 in conversation