BookmarkSubscribeRSS Feed
knighsson
Obsidian | Level 7
My code is below.
The variable "Occ_Time" is in the format of "DATETIME." in the original dataset, but when I print out the new dataset, it becomes numbers such as "1961799000". Can you please teach me how to format the "Occ_Time" as DATETIME. in the new dataset ? Thank you!
 
 
proc transpose data=el.OCC  out=el.wide prefix=Occ_Name_;
by UserName_numbers RecallNo;
    var Occ_Name Occ_Time ;
format Occ_Time DATETIME.;
run;
7 REPLIES 7
PaigeMiller
Diamond | Level 26

I'm not sure what the problem is, as you didn't share a portion of your real data with us. Please do that, following these examples and instructions.

 

As things stand now, I cannot reproduce this problem.

 

data fake;
    occ_time='01JAN2024:00:00:00'dt; output;
    occ_time='01JAN2024:01:15:00'dt; output;
    format occ_time datetime.;
run;

proc transpose data=fake out=transp prefix=occ_name_;
    var occ_time;
run;

 

Produces this output

 

PaigeMiller_0-1704220815340.png

 

--
Paige Miller
knighsson
Obsidian | Level 7

Thank you for your response. 

The original dataset looks like this:Capture.PNG

 

The wanted/new dataset looks like this:

Capture2.PNG

But I want the "Occ-Time" is still as "DATETIME." format rather than numbers.

 

Thank you!

 

 

Tom
Super User Tom
Super User

Your code looks correct.  Here is an example you can run for yourself.

 

data have;
  do now=datetime(),datetime()+'24:00:00't ;
    output;
  end;
run;
proc print;
run;

proc transpose data=have out=want1 ;
 var now;
run;
proc print;
run;

proc transpose data=have out=want2 ;
 var now;
 format now datetime19.;
run;
proc print;
run;

 

But perhaps the variable names are not what you think they are?

 

Your picture seems to have two columns with a header of OCC_TIME.

Which one did you use when you created the variable named OCC_TIME you used in your SAS code?  What format did it have attached to it?

 

knighsson
Obsidian | Level 7

Thank you!

PaigeMiller
Diamond | Level 26

What happens if in PROC TRANSPOSE you use

 

proc transpose data=el.OCC  out=el.wide prefix=Occ_Name_;
    by UserName_numbers RecallNo;
    var Occ_Time ;
run;
--
Paige Miller
knighsson
Obsidian | Level 7

Ok, this will work. Thank you!

ballardw
Super User

Actually in SAS your starting data cannot appear as shown as you show two variables named OCC_time and SAS will not allow that in a single data set. One of those is apparently a TIME value and the other a DATETIME value. If you transpose data so that both values end up in the same variable then you have a mix of time and datetime values in the variable and which ever format is attempted will display one of the values incorrectly.

 


@knighsson wrote:

Thank you for your response. 

The original dataset looks like this:Capture.PNG

 

The wanted/new dataset looks like this:

Capture2.PNG

But I want the "Occ-Time" is still as "DATETIME." format rather than numbers.

 

Thank you!

 

 


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 612 views
  • 0 likes
  • 4 in conversation