BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ganeshk
Obsidian | Level 7

 

Hi Team,

 

I used the proc format procedure on data set:

 

image.png

 

I am getting missing values as "ERROR" instead of "." missing value.

 

image.png

 

How to fix the issue, from "ERROR" to missing(.) value?

 

Thanks,

Ganesh K

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Just add a proper definition for missing values:

proc format;
picture dtpic
  . = ' '
  other = '%Y-%0m-%0d %0H:%0M:%0S'
  (datatype=datetime)
;
run;

data test;
input ID ID_C Date1 Date2;
format date1 date2 dtpic.;
datalines;
343 565 1.8362E9 .
3435 4546 . -3.592E9
;
run;

proc print data=test noobs;
run;

Result:

 ID     ID_C           Date1                  Date2

 343     565    2018-03-09 07:33:20                       
3435    4546                           1846-03-04 22:13:20

 

View solution in original post

17 REPLIES 17
PeterClemmensen
Tourmaline | Level 20

Why do you type %proc format?

 

Show us your code that generates data.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As @PeterClemmensen  states, % invokes the macro pre-processor, it should never appear in front of the word proc which is a reserved word in SAS.

andreas_lds
Jade | Level 19

Please post the log containing the execution of that proc format, i am 100% sure that you get an error message, complaining about "%proc".

Ganeshk
Obsidian | Level 7

% was Typo error before taking snap shot. I checked Log, there is no error.

 

image.png

 

 

Actually problem is different, in output i am getting "ERROR" for missing value.

 

Kurt_Bremser
Super User

Fix this ERROR first:

15         %proc format;
           _
           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

Debugging needs to be done top-down. Fixing the first ERROR/WARNING in your code might prevent all others from happening.

Ganeshk
Obsidian | Level 7

No Error in Log. Its Typo before taking screen shot. Require Solution as posted above. could you please give some thought.

Kurt_Bremser
Super User

Please post code as text (see my footnotes) by simply copy/pasting from SAS to a window opened with the "little running man".

And supply example data in usable form, again see my footnotes. Help us to help you.

Your format works:

proc format;
picture dtpic
  other='%Y-%0m-%0d %0H:%0M:%0S ' (datatype=datetime);
run;

data test;
date1 = datetime();
format date1 dtpic.;
run;

proc print data=test noobs;
run;

Log of the data step:

42         data test;
43         date1 = datetime();
44         format date1 dtpic.;
45         run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

Result:

       date1

2019-01-25 12:48:47
Ganeshk
Obsidian | Level 7

Since the value for date exist, "ERROR" wont be depicted. What if the missing value exist in Second record. In my case i have missing value.

 

 

 

Ksharp
Super User
proc format;
picture dtpic
  low-high='%Y-%0m-%0d %0H:%0M:%0S ' (datatype=datetime);
run;

data test;
date1=.;output;
date1 = datetime();output;
format date1 dtpic.;
run;
Ganeshk
Obsidian | Level 7

Hi  Ksharp,

 

Thanks for reply.  Here is the sample data set which i have prepared for you:

 

data art;

input ID ID_C Date1 Date2;

datalines;

343 565 1.8362E9 .

3435 4546 . -3.592E9

;

 

proc format;

     picture dtpic

 

          other='%Y-%0m-%0d %0H:%0M:%0S ' ( datatype=datetime);

run;

 

data test;

set art;

format Date1 dtpic.;

format Date2 dtpic.;

run;

    

Please help me to resolve with above code.

 

Thanks,

Ganesh K

Kurt_Bremser
Super User

Just add a proper definition for missing values:

proc format;
picture dtpic
  . = ' '
  other = '%Y-%0m-%0d %0H:%0M:%0S'
  (datatype=datetime)
;
run;

data test;
input ID ID_C Date1 Date2;
format date1 date2 dtpic.;
datalines;
343 565 1.8362E9 .
3435 4546 . -3.592E9
;
run;

proc print data=test noobs;
run;

Result:

 ID     ID_C           Date1                  Date2

 343     565    2018-03-09 07:33:20                       
3435    4546                           1846-03-04 22:13:20

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Interestingly, that does not work for me.  

 

data art;
  input id id_c date1 date2;
datalines;
343 565 1.8362E9 .
3435 4546 . -3.592E9
;
run;
 
proc format;
  picture dtpic
    . = ' '
    other='%Y-%0m-%0d %0H:%0M:%0S ' ( datatype=datetime);
run;

data test;
  set art;
  format date1 date2 dtpic.;
run;

proc print data=test;
run;

 

                                         The SAS System        13:43 Friday, January 25, 2019   1

            Obs     id     id_c    date1                      date2

             1      343     565        2018-03-09 07:33:20    ERROR                  
             2     3435    4546    ERROR                          1846-03-04 22:13:20

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 1703 views
  • 7 likes
  • 6 in conversation