Programming the statistical procedures from SAS

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

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

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: 18,566

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: 18,566

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

Super User
Posts: 5,250

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.

Respected Advisor
Posts: 3,780

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,250

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

Bingo!  Good job.

Respected Advisor
Posts: 3,780

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

The "SAS Variable List"  big medicine.

Respected Advisor
Posts: 3,147

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

Respected Advisor
Posts: 3,780

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;
Respected Advisor
Posts: 3,147

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. Smiley Happy

Haikuo

Respected Advisor
Posts: 3,780

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?

Respected Advisor
Posts: 3,780

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

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: 18,566

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 21 replies
  • 2099 views
  • 4 likes
  • 7 in conversation