DATA Step, Macro, Functions and more

Help in user created format

Reply
Super Contributor
Posts: 272

Help in user created format

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

Super User
Posts: 11,343

Re: Help in user created format

Posted in reply to knveraraju91

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;
Valued Guide
Posts: 505

Re: Help in user created format

Posted in reply to knveraraju91
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
Super Contributor
Posts: 272

Re: Help in user created format

Posted in reply to rogerjdeangelis

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;

Super User
Posts: 19,806

Re: Help in user created format

Posted in reply to knveraraju91

Report this to SAS Tech Support. But I do remember a vague idea of a bug with SAS Studio and creating formats.

Valued Guide
Posts: 505

Re: Help in user created format

Posted in reply to knveraraju91

 

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

 

Trusted Advisor
Posts: 1,566

Re: Help in user created format

Posted in reply to knveraraju91

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.

Super User
Posts: 19,806

Re: Help in user created format

@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;
Super User
Posts: 11,343

Re: Help in user created format


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.

Trusted Advisor
Posts: 1,566

Re: Help in user created format

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

Super User
Posts: 19,806

Re: Help in user created format

Posted in reply to knveraraju91

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;

 

 

Super User
Posts: 10,028

Re: Help in user created format

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

Super Contributor
Posts: 272

Re: Help in user created format

Thank you very much

Ask a Question
Discussion stats
  • 12 replies
  • 298 views
  • 1 like
  • 6 in conversation