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: 20,731

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

Posted in reply to sandyming

All Replies
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)?

Posted in reply to sandyming
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.

Respected Advisor
Posts: 3,805

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

Posted in reply to Astounding

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)?

Posted in reply to data_null__

Bingo!  Good job.

Respected Advisor
Posts: 3,805

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

Posted in reply to Astounding

The "SAS Variable List"  big medicine.

Respected Advisor
Posts: 3,157

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

Posted in reply to Astounding

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

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

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

Posted in reply to data_null__

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

Haikuo

Respected Advisor
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?

Respected Advisor
Posts: 3,805

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

Posted in reply to sandyming

No

Contributor
Posts: 32

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

Posted in reply to data_null__

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)?

Posted in reply to sandyming

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
  • 2317 views
  • 4 likes
  • 7 in conversation