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

Can anyone help me to replicate this error with same data step? User of my program having this error however I'm not able to replicate it at my end in order to debug:

At my end, it just works fine.

 



data abc; length studyid $200; set abc; studyid=upcase("subject_level_data"); *This 'subject_level_data' value comes from macro a macro variable) run; ERROR: Width specified for format F is invalid.

Additional info: 

 - User gets his data imported from STATA V16

- data abc doesn't have pre-existing studyid variable. (however you can try if that helps to replicate the error)

- User using SAS 9.4

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Format F is for numerical variables so the Error has likely nothing to do with variable studyid. The maximum length for F is 32 and you can generate the error by using a higher value.

27         
28         data abc;
29           var=10;
30           format var f33.;
                        ____
                        29
ERROR 29-185: Width specified for format F is invalid.

May be the Stata V16 import creates this format with a too high length and you then get the error simply by using the table in the SET statement. 

Eventually execute a Proc Contents for table abc and verify the assigned formats there.

View solution in original post

7 REPLIES 7
Patrick
Opal | Level 21

Format F is for numerical variables so the Error has likely nothing to do with variable studyid. The maximum length for F is 32 and you can generate the error by using a higher value.

27         
28         data abc;
29           var=10;
30           format var f33.;
                        ____
                        29
ERROR 29-185: Width specified for format F is invalid.

May be the Stata V16 import creates this format with a too high length and you then get the error simply by using the table in the SET statement. 

Eventually execute a Proc Contents for table abc and verify the assigned formats there.

Lenith
Obsidian | Level 7

Okay, seems its way to go. Since now i can stop thinking about the Studyid variable (earlier I thought it's related to the length of Studyid variable), I can look for other possibilities as you suggested.

 

I got Proc contents of the data and there is one numeric variable where format shows 44. That could be the potential issue. I'll ask him to remove and test the program. Hopefully it works. 

 

Will update here about the result.

Patrick
Opal | Level 21

Here to fully simulate the error how you encounter it. Proc Dataset didn't let me select an invalid width for format F but Proc SQL/Alter Table does. And that's also how you could change the format in the table to a valid width for SAS.

This is definitely Stata creating an XPORT file with an invalid SAS format attached. The question is of course why this format is so wide and if this is eventually an effect of a numerical variable in Stata with too many digits for SAS to store with full precision (8 bytes/max 15 digits). So besides of just "make the error go away" it's eventually also worth to look a bit deeper and investigate if there is also some truncation/precision issue.

data abc;
  var=10;
run;

proc sql;
  alter table abc
    modify var format=f33.
    ;
quit;

data test;
  set abc;
run;
37         
38         data test;
39           set abc;
40         run;

ERROR: Width specified for format F is invalid.
Lenith
Obsidian | Level 7

Completely agree with you on this. It worth checking the precision issue if any (maybe topic for another thread), however in my case it wouldn't be an issue as variable is integer categorical and I don't expect a big number there. Thank you for the hint.

 

 

Kurt_Bremser
Super User

@Lenith wrote:

.... variable is integer categorical 

 


Then it should not be stored as a number in the first place. There are many SAS applications and procedures where categories MUST be character. So you should convert/correct that, even if precision is not an issue.

Lenith
Obsidian | Level 7

Yes, it could be, however I'm not the one to decide in my scenario. From what I have experienced, most of the stats/modling experts prefer numeric variable (even categorical one) for their analysis/modeling purpose. That could be one of the reason to keep it as numeric. 

Lenith
Obsidian | Level 7

Just to update, Error has been fixed after removing the format from the numeric variable having > F32. format.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 14796 views
  • 5 likes
  • 3 in conversation