Friday, November 18, 2011

SAS Error "Width specified for format F is invalid."

I came across the SAS error "ERROR: Width specified for format F is invalid." As that provides absolutely no hint as to what the actual problem is, it took me forever to figure it out.

What I've determined is it's a result of importing a file using proc import. Apparently there is some variable SAS doesn't like in that file (if you know exactly why, I'm all ears).

The solution is to write a "format _all_;" statement in a data step for the file before anything else is done to it. Something like this:

proc import datafile="your file" out=mydataset replace;
run;

data mydataset;
set mydataset;
format _all_;
run;

I hope it helps!

31 comments:

  1. Thank you so much you save me...
    Your blog is much better than SAS's help.
    Thank you again from knoxville, TN!

    ReplyDelete
  2. Your article saved me!!!

    ReplyDelete
  3. Wonderful! This was so very helpful. Thanks for the post (and the XKCD cartoon)!

    ReplyDelete
  4. Thank you, I really appreciate your help. I had the same problem with a Put statement. It was IF F2= " " THEN NAME=PUT(INCIDENT_ID, 35.); that caused the problem. Then I realized that I was creating INCIDENT_ID in that statement. I really needed to use IF F2= " " THEN NAME=PUT(F1, 35.); because I had not named the variables yet.

    ReplyDelete
  5. Thank you for posting this! This post saved me so much time!!

    ReplyDelete
  6. I just typed the error and the link popped up and boom it is solved ..thanks a ton!!

    ReplyDelete
  7. Thanks! You can also view this in SAS help but credits to you still. :)

    ReplyDelete
  8. Thank you-- this formatting fix allows me to use my imported SPSS file, but it changes my Date variables to a number (I assume the SAS date number) (eg. upon first import by DOB variable is 25JUL1989:00:00:00 following format DATETIME20. and then I apply the _all_ and it changes to 932947200 following format Best12.). I tried to use formatting code to convert the date variables back to their correct date, but it doesn't work. The formatting is accepted, but the variable remains a the same number (eg. despite successfully applying any number of date formats,eg. Date. or the original date format datetime20. it remains the number 932947200). Do you have any suggestions?

    ReplyDelete
  9. I applied format_all_; but all the categories names for categorical variables were replaced with the original numeric codes created in SPSS file. Please help.

    ReplyDelete
  10. о да! Thank you very-very much!)

    ReplyDelete
  11. It indeed helped me today when i came across a similar scenario. Thanks for sharing

    ReplyDelete
  12. THANK YOU SO MUCH!

    ReplyDelete
  13. Thank you so much for making this so easy!

    ReplyDelete
    Replies
    1. You're welcome! I'm glad that still 7 years later it can be helpful! :-)

      Delete
  14. You have saved my life! Thank you SO much

    ReplyDelete
  15. THANK YOU!!!!!!!!!!!!!!!!!

    ReplyDelete
  16. Life savior! Thank you so much!

    ReplyDelete
  17. Thank you very much. This is very helpful.

    ReplyDelete
  18. It fixed the problem with merging, but wipes out all formats. I've got some variables with 1-2 dozen formatted values, which were replaced with numbers.

    ReplyDelete
  19. Many thanks - completely solved a problem I was struggling with after reading in an SPSS dataset

    ReplyDelete
    Replies
    1. same here. Not happy that I couldn't just wipe the format for the single variable that was causing the problem. But it works for now.

      Delete
  20. Wasted one whole hour trying to read and understand SAS documentation. and then Viola! Thank you from NYC!

    ReplyDelete
  21. super helpful, even 8-9 years after your original posting. Thank you!! :)

    ReplyDelete
  22. I just got saved. Thanks

    ReplyDelete
  23. 토토랜 4-pack naija kami game - Online 우리카지노 계열사 우리카지노 계열사 바카라사이트 바카라사이트 クイーンカジノ クイーンカジノ 746BETGames TV Lucky 5 Videos - VntopBet

    ReplyDelete
  24. Thanks and I have a neat present: Where To Learn Home Renovation complete house renovation cost

    ReplyDelete