Solved
Contributor
Posts: 32

# how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

using Code in a Data step...

Accepted Solutions
Solution
‎06-30-2017 12:38 PM
Super User
Posts: 20,731

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

All Replies
Solution
‎06-30-2017 12:38 PM
Super User
Posts: 20,731

Super User
Posts: 5,724

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

OK, now here's a harder question.  How do you do it in a PROC step?  For example, if T is character, it should be printed without a format.  But if T is numeric it should be printed in the TIME5 format.  Hint:  macro language is not needed.  All of the necessary code can be hard-coded within the PROC step.  If nobody gets the answer, I'll post it tonight.

Posts: 3,805

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

It this right?

format t-numeric-t time5.;

Super User
Posts: 5,724

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

Bingo!  Good job.

Posts: 3,805

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

The "SAS Variable List"  big medicine.

Posts: 3,157

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

Confused. Never seen this before. Care to elaborate more? Thanks, Haikuo

Posts: 3,805

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

It means for all the variables between t and t that are numeric associate format time5.  If there are none when t is character nothing happens.

SAS(R) 9.3 Language Reference: Concepts, Second Edition

data class;
set sashelp.class;
*t = time();
t =
'8:01';

run;
proc print;

format t-numeric-t time5.;

run;
Posts: 3,157

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

Thanks for the explanation and specially,  the link. Did not know such things existed.

Haikuo

Posts: 3,805

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

Just to make it more complete  we can also format the character name range T, that may or may not exist.  The "SAS Variable List" is one of the most powerfull parts of the SAS language.

format t-numeric-t time5. t-character-t \$5.;
Contributor
Posts: 32

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

If in a macro:

%if "vtype(&time)"="C" %then %do....

is this correct?

Posts: 3,805

No

Contributor
Posts: 32

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

why it is not correct? how about : if vtype(&tm)="N"?

Super User
Posts: 20,731

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

What are you trying to do?

Contributor
Posts: 32

## Re: how to identify a time variable (time5. format) is num or char, not using (Proc Content)?

if the time variable is char, then do something;

if it is num, do something else....

🔒 This topic is solved and locked.