Re: [R] Problems with foreign

2023-03-30 Thread David Winsemius



On 3/30/23 10:36, José Oscar Delgado Bautista wrote:

  Good day
My name is José Oscar, I'm from Mexico and I have some questions about
foreign in your write.foreig( ) function. We know that this function
generates the inputs to be able to run them or execute them in another
program like SPSS, SAS or Stata. In these cases, when creating an example
file, a matrix and using the function to execute the .sps file directly
from SPSS, I don't care or work based on the SPSS environment. With Stata
the problem does not arise, but this same problem also arises with SAS, in
that sense or question, how could I solve this? Do you have any guides or
tutorials on the correct use of the function?


I don't really understand the question. Not sure what the problem you 
are seeing when you attempt to get SAS-style output. I went to the help 
page for `write.foreign`:


?write.foreign

...  and the Arguments section clearly shows that although "SPSS" is the 
default value, that any of the other recognized values for the format of 
the output would be accepted.


Perhaps you are so inexperienced with R that you don't even know how to 
access the help system?



This is the code:
x<- matrix(data = sample(1:100,
  100),
nrow = 10, ncol = 10)

x2<- as.data.frame(x)

write.foreign(x2, "x2_spss.txt", "x2_spss.sps", package = "SPSS")


When I changed the "package" argument to "SAS", ...  I get SAS code:

* Written by R;
*  write.foreign(esoph, datafile, codefile, package = "SAS") ;

PROC FORMAT;
value agegp
 1 = "25-34"
 2 = "35-44"
 3 = "45-54"
 4 = "55-64"
 5 = "65-74"
 6 = "75+"
;

value alcgp
 1 = "0-39g/day"
 2 = "40-79"
 3 = "80-119"
 4 = "120+"
;

value tobgp
 1 = "0-9g/day"
 2 = "10-19"
 3 = "20-29"
 4 = "30+"
;

DATA  rdata ;
INFILE  "/tmp/RtmpFcHZ9L/file6a7222461f1c"
 DSD
 LRECL= 15 ;
INPUT
 agegp
 alcgp
 tobgp
 ncases
 ncontrols
;
FORMAT agegp agegp. ;
FORMAT alcgp alcgp. ;
FORMAT tobgp tobgp. ;
RUN;

--

David.



[[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.


__
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.


[R] Problems with foreign

2023-03-30 Thread José Oscar Delgado Bautista
 Good day
My name is José Oscar, I'm from Mexico and I have some questions about
foreign in your write.foreig( ) function. We know that this function
generates the inputs to be able to run them or execute them in another
program like SPSS, SAS or Stata. In these cases, when creating an example
file, a matrix and using the function to execute the .sps file directly
from SPSS, I don't care or work based on the SPSS environment. With Stata
the problem does not arise, but this same problem also arises with SAS, in
that sense or question, how could I solve this? Do you have any guides or
tutorials on the correct use of the function?

This is the code:
x<- matrix(data = sample(1:100,
 100),
   nrow = 10, ncol = 10)

x2<- as.data.frame(x)

write.foreign(x2, "x2_spss.txt", "x2_spss.sps", package = "SPSS")

[[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.