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

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

 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

13 REPLIES 13
HB
Barite | Level 11 HB
Barite | Level 11

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

 

 

aminkarimid
Lapis Lazuli | Level 10
Yes HB.
aminkarimid
Lapis Lazuli | Level 10
Yes ChrisNZ.
ChrisNZ
Tourmaline | Level 20
What you want is called formatting.
Why do you say you don't want it?
aminkarimid
Lapis Lazuli | Level 10
Initial date and time variable were character and I formatted them to
numeric.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
ChrisNZ
Tourmaline | Level 20

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.;
aminkarimid
Lapis Lazuli | Level 10
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.
ChrisNZ
Tourmaline | Level 20

How about this?

data SAMPLEDATA01;
  set SAMPLEDATA;
  TRD_EVENT_DT = datepart(TRD_EVENT_DT);
  format TRD_EVENT_DT date9. TRD_EVENT_TM time.;
run;
aminkarimid
Lapis Lazuli | Level 10
ERROR 48-59: The format $TIME was not found or could not be loaded.
ChrisNZ
Tourmaline | Level 20

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

 

$ formats are for character variables.

ChrisNZ
Tourmaline | Level 20

Or do you have a character variable?

 

What exactly do you have?

 

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

Tom
Super User Tom
Super User

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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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