BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

I would like to transform a time8. Dataset column to a $CHAR8. Column to represent, for example, 15:47:39 as the same string/$CHAR8. Not SAS’s internal representation. I tried:

 

 

SomeTime=put(SomeTime,time8.);
format SomeTime $CHAR8.;

 

in my dataset without success. Any ideas? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@csetzkorn wrote:

I would like to transform a time8. Dataset column to a $CHAR8. Column to represent, for example, 15:47:39 as the same string/$CHAR8. Not SAS’s internal representation. I tried:

 

 

SomeTime=put(SomeTime,time8.);
format SomeTime $CHAR8.;

 

in my dataset without success. Any ideas? Thanks!


You always have to create a new variable when you want to switch types.

So you might do

data want;
set have (rename=(sometime=_sometime));
length sometime $8;
sometime = put(_sometime,time8.);
drop _sometime;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

In general, it should not be necessary, as far as I can think of examples, to turn a SAS time (or date or datetime) value to a character variable. It seems like you are making your life difficult for yourself.

 

However, in your code, the variable SomeTime cannot be both numeric and character. It is numeric. If you want a character variable, you have to give it a different variable name.

--
Paige Miller
Rick_SAS
SAS Super FREQ

Two ways: use PUT or if the variable already has a format, you can use VVALUE to get the formatted valu:

 

data A;
length str str2 $8;
format time time8.;
time = '15:47:39't;
str = put(time, time8.);
str2 = vvalue(time);
run;

proc print; run;
Kurt_Bremser
Super User

@csetzkorn wrote:

I would like to transform a time8. Dataset column to a $CHAR8. Column to represent, for example, 15:47:39 as the same string/$CHAR8. Not SAS’s internal representation. I tried:

 

 

SomeTime=put(SomeTime,time8.);
format SomeTime $CHAR8.;

 

in my dataset without success. Any ideas? Thanks!


You always have to create a new variable when you want to switch types.

So you might do

data want;
set have (rename=(sometime=_sometime));
length sometime $8;
sometime = put(_sometime,time8.);
drop _sometime;
run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 2555 views
  • 3 likes
  • 4 in conversation