Dear,
I am using the following format. I am not getting the output for the data values. Please help. Thank you
proc format;
picture fmt(default=10)
other='%n %0H:%0M'(datatype=time);
run;
code;
value=strip(put((AEDATE-TRTDATE),fmt.));
data
aedate trtdate
29JUL15:15:00 28JUL15:08:45
output getting;
1 30:15
output need
1 06:15
I suggest rechecking your values of the datetime variables. For your example data I get 06:15
Here is the code I used to assign values and test:
data junk; aedate = "29JUL15:15:00"dt; trtdate= "28JUL15:08:45"dt; format aedate trtdate datetime20.; value=strip(put((AEDATE-TRTDATE),fmt.)); run;
I get the result you want
proc format;
picture fmt(default=10)
other='%n %0H:%0M'(datatype=time);
run;
data have;
aedate = '29JUL15:15:00'dt;
trtdate = '28JUL15:08:45'dt;
dur=AEDATE-TRTDATE;
durc=put(dur,fmt12.);
put durc;
run;quit;
1 06:15
Thanks for the help. You are right.
when I run your code in sas on my desk top , I got the what you got.
But when I run in sas on my remote desk top, i am getting 1 30:15.
Do you any suggestions. Thanks
proc format;
picture fmt(default=10)
other='%n %0H:%0M'(datatype=time);
run;
data have;
aedate = '29JUL15:15:00'dt;
trtdate = '28JUL15:08:45'dt;
dur=AEDATE-TRTDATE;
durc=put(dur,fmt12.);
put durc;
run;
Report this to SAS Tech Support. But I do remember a vague idea of a bug with SAS Studio and creating formats.
I get the result you want
proc format;
picture fmt(default=10)
other='%n %0H:%0M'(datatype=time);
run;
data have;
aedate = '29JUL15:15:00'dt;
trtdate = '28JUL15:08:45'dt;
dur=AEDATE-TRTDATE;
durc=put(dur,fmt12.);
put durc;
run;quit;
1 06:15
When I use format line:
other='%n %0H:%0M'(datatype=time);
I get ERROR message:
ERROR: An unknown, abnormal error has occured etc.
I changed into:
other='%n %0H:%0M'(datatype=datetime);
then it is running without error but I get
result = 0 06:01
Then I changed the line into:
other='%d %0H:%0M'(datatype=datetime);
and i get : result = 2 06:01
though when I code
diff = '29JUL15:15:00'dt - '28JUL15:08:45'dt;
put diff= time7. ;
the result is 30:15 which is actually 1 06:15
I have used same data values as posted, that is: 29JUL15:15:00 28JUL15:08:45
I admit that I could not solve it, using SAS UE on linux.
@Shmuel There were no errors on BASE SAS. I wonder if it's an artifact. If I use type = datetime the incorrect values are generated.
PS. I would recommend the word day or something in that format, its not obviously clear how to read that value at all.
proc format;
picture myfmt(default=20)
other='%n Day %0H:%0M'(datatype=time);
run;
@Shmuel wrote:
When I use format line:
other='%n %0H:%0M'(datatype=time);
I get ERROR message:
ERROR: An unknown, abnormal error has occured etc.
@Shmuel Sometimes I get artifacts in code copied from the forum that causes similar errors. Sometimes when editing those lines I will attempt to delete a character but it is still there indicating possibly a bad unicode or other character translation to the editor. I did not get any error from the shown format code though.
@ballardw, @Reeza - as I wrote I'm using SAS UE on linux in my laptop.
I use a PC with windows for the forum, so I don't use copy/paste.
In that specific case I typed data and code, and changing just "time" to "datetime"
prevented the error.
Restarting my SAS session didn't help;
I'll check it again some day later.
Thanks, again.
The correct answers are either:
1 06:15 or 30:15
ie 30 hours and 15 minutes of wait time to treatment - that's horrid by the way.
I think you may be misreading the 30:15 somehow? Slight modification of Roger's answer to show both values.
data junk;
aedate = "29JUL15:15:00"dt;
trtdate= "28JUL15:08:45"dt;
format aedate trtdate datetime20. diff myfmt. diff2 time8.;
diff=AEDATE-TRTDATE;
diff2=aedate-trtdate;
diff_char=put(diff, myfmt.);
run;
proc print data=junk NOOBS;
var diff:;
run;
According documentation said, %n can't be used in all the encoding sas session. e.g. if you are using University Edition ,you will get wrong result due to its utf-8 encoding. So try other ways.
Thank you very much
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.