How to read data and time as a numeric variable?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 107
Accepted Solution

How to read data and time as a numeric variable?

Hello everybody,

I have numeric variables which are showed below:

 

SAS Output:

 
Checking numeric variables in the patients data set
      
The MEANS Procedure    
      
VariableLabelNN MissMinimumMaximum
PricePrice2117458900.854050002
TurnoverTurnover21174589019.84E+08
Datedate2117458901761519435
Time 2117458903064982126

 

I don't want to format variables and just want to read date and time variables of this table like hh:mm and dd:mm:yy.

 

How can I do that?

 

Thanks in advance

 

Accepted Solutions
Solution
3 weeks ago
Super User
Super User
Posts: 6,500

Re: How to read data and time as a numeric variable?

How much does the format of the table matter to you?

Why not just have PROC MEANS generate a dataset and then print that?

data test;
 input id $ price turnover date time;
 format date date9. time time5. ;
cards;
min 0.85 1 17615 30649
max 4050002 9.84E+08 19435 82126
;

proc means noprint data=test;
 output out=xx ;
run;

proc print data=xx;
 where _stat_='N';
 format _all_;
run;

proc print data=xx;
 where _stat_ in ('MIN','MAX');
run;
Obs    _TYPE_    _FREQ_    _STAT_    price    turnover    date    time

 1        0         2        N         2          2         2       2


Obs    _TYPE_    _FREQ_    _STAT_         price     turnover         date     time

 2        0         2       MIN            0.85            1    24MAR2008     8:30
 3        0         2       MAX      4050002.00    984000000    18MAR2013    22:48

View solution in original post


All Replies
Frequent Contributor
Frequent Contributor
Posts: 89

Re: How to read data and time as a numeric variable?

Are you asking to have PROC MEANS display the minimum date as 21Jul1969 instead of 3489?

 

 

Frequent Contributor
Posts: 107

Re: How to read data and time as a numeric variable?

Yes HB.
PROC Star
Posts: 1,561

Re: How to read data and time as a numeric variable?

Did you paste this table from Excel?

Frequent Contributor
Posts: 107

Re: How to read data and time as a numeric variable?

Yes ChrisNZ.
PROC Star
Posts: 1,561

Re: How to read data and time as a numeric variable?

What you want is called formatting.
Why do you say you don't want it?
Frequent Contributor
Posts: 107

Re: How to read data and time as a numeric variable?

Initial date and time variable were character and I formatted them to
numeric.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
PROC Star
Posts: 1,561

Re: How to read data and time as a numeric variable?

Just a bit of terminology so we all speak the same language:

Initial date and time variable were character were *converted*  to numeric, and now you want them *formatted* to date and time.

 

That's done with a format statement. For example:

format  DATEVAR date9.  TIMEVAR time.;
Frequent Contributor
Posts: 107

Re: How to read data and time as a numeric variable?

Here is my code which is used to convert character variables to numeric:

data sampledata01;
set sampledata;
trd_event_dt = datepart(trd_event_dt);
format trd_event_dt date9.;
new_var = input(TRD_EVENT_TM,hhmmss.);
format new_var time5.;
drop TRD_EVENT_TM;
rename new_var = TRD_EVENT_TM;
run;

Explanation:
The trd_event_dt is Date.
The TRD_EVENT_TM is Time.
PROC Star
Posts: 1,561

Re: How to read data and time as a numeric variable?

How about this?

data SAMPLEDATA01;
  set SAMPLEDATA;
  TRD_EVENT_DT = datepart(TRD_EVENT_DT);
  format TRD_EVENT_DT date9. TRD_EVENT_TM time.;
run;
Frequent Contributor
Posts: 107

Re: How to read data and time as a numeric variable?

ERROR 48-59: The format $TIME was not found or could not be loaded.
PROC Star
Posts: 1,561

Re: How to read data and time as a numeric variable?

Where did you see a $ in the code I posted?

 

$ formats are for character variables.

PROC Star
Posts: 1,561

Re: How to read data and time as a numeric variable?

Or do you have a character variable?

 

What exactly do you have?

 

Provide: variable name, type, and value, for each of the 2 variables.

Solution
3 weeks ago
Super User
Super User
Posts: 6,500

Re: How to read data and time as a numeric variable?

How much does the format of the table matter to you?

Why not just have PROC MEANS generate a dataset and then print that?

data test;
 input id $ price turnover date time;
 format date date9. time time5. ;
cards;
min 0.85 1 17615 30649
max 4050002 9.84E+08 19435 82126
;

proc means noprint data=test;
 output out=xx ;
run;

proc print data=xx;
 where _stat_='N';
 format _all_;
run;

proc print data=xx;
 where _stat_ in ('MIN','MAX');
run;
Obs    _TYPE_    _FREQ_    _STAT_    price    turnover    date    time

 1        0         2        N         2          2         2       2


Obs    _TYPE_    _FREQ_    _STAT_         price     turnover         date     time

 2        0         2       MIN            0.85            1    24MAR2008     8:30
 3        0         2       MAX      4050002.00    984000000    18MAR2013    22:48
☑ This topic is SOLVED.

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

Discussion stats
  • 13 replies
  • 299 views
  • 1 like
  • 4 in conversation