Hi Team,
I used the proc format procedure on data set:
I am getting missing values as "ERROR" instead of "." missing value.
How to fix the issue, from "ERROR" to missing(.) value?
Thanks,
Ganesh K
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
Why do you type %proc format?
Show us your code that generates data.
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.
Please post the log containing the execution of that proc format, i am 100% sure that you get an error message, complaining about "%proc".
% was Typo error before taking snap shot. I checked Log, there is no error.
Actually problem is different, in output i am getting "ERROR" for missing value.
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.
No Error in Log. Its Typo before taking screen shot. Require Solution as posted above. could you please give some thought.
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
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.
POST
WHOLE
CODE
AND
EXAMPLE
DATA
IN
USABLE
FORM
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;
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
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
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
Interesting indeed. I'm on 9.4M5 on AIX, and get no ERROR for the missing values.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.