I haven’t used this function in a long time, but it sounds like the issue is 
the format names for the formats catalog, not the variable names.

You might try the haven package as it can create SAS datasets directly, 
although there are limitations (I think).

> On Jun 6, 2024, at 4:45 AM, Julien JOLY <julien.j...@inserm.fr> wrote:
> 
> [Vous ne recevez pas souvent de courriers de julien.j...@inserm.fr. D?couvrez 
> pourquoi ceci est important ? https://aka.ms/LearnAboutSenderIdentification ]
> 
> Dear all,
> 
> First of all, I thank you for the creation of the package.
> 
> I write this message concerning the write.foreign() function from the foreign 
> package and a bug that I discovered.
> When we want to save our dataset as a .sas file, the limit of variable names 
> character is 8 by default. In SAS this limit is 32 character and an argument 
> in the function, validvarname, can theorically switch the default from 8 to 
> 32 by selecting validvarname = "V7".
> 
> However, it did not work and show the error "Cannot uniquely abbreviate 
> format names to conform to eight-character limit and not ending in a digit" 
> that show the limit is still 8 characters.
> 
> By looking at the script at 
> https://github.com/cran/foreign/blob/master/R/writeForeignSAS.R , I realized 
> that the line 39, in the function make.SAS.formats, can be the reason of the 
> nonfunctioning argument :
> "if(any(nchar(x) > 8L) || any(duplicated(x)))" which is correct if the length 
> of the variable has a limit of 8, but it does not take in consideration when 
> the limit is at 32 defined by validvarnames = "V7".
> 
> A solution can be to add the argument validvarname in the definition of the 
> function and add these few lines :
>  validvarname <- match.arg(validvarname)
>  nmax <- if(validvarname == "V7") 32L else 8L
>  if(any(nchar(x) > nmax) || any(duplicated(x)))
> 
> 
> I hope I send the message to the good place and that it will help you improve 
> the package.
> 
> Kind regards,
> 
> 
> 
> Julien Joly
> 
> Biostatisticien et Data manager
> 
> 
> 
> 
> 
>        [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Kevin E. Thorpe
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416-946-8083


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to