Hi everyone, I would like to send a SAS dataset to R with the formatted values. When I use ExportDataSetToR the dataset is sent with the unformatted values. Any help on how I can retain formatted values? Here is a toy example
data have;
input x $;
datalines;
A
B
;
proc format;
value $x 'A'='One'
'B'='Two';
run;
data have; set have; format x $x.; run;
proc iml;
call ExportDataSetToR("have","want");
submit / R;
want
endsubmit;
quit;
In this example the values 'A' and 'B' show in R instead of 'One' and 'Two'
Thanks!
R doesn't have formats, which is why the formats get stripped out (except for data, time, and datetime). If you want to send in the formatted data, you can use the PUT function to create the formatted values in a separate variable:
proc format;
value $x 'A'='One'
'B'='Two';
run;
data have;
input x $;
format x $x.;
datalines;
A
B
;
data want;
set have(rename=(x=xRaw)); /* rename the raw data */
length x $3; /* =max length of formmatted values */
x = put(xRaw, $x.); /* new var w/ formatted values */
run;
proc iml;
call ExportDataSetToR("want","wantInR");
submit / R;
wantInR
endsubmit;
quit;
R doesn't have formats, which is why the formats get stripped out (except for data, time, and datetime). If you want to send in the formatted data, you can use the PUT function to create the formatted values in a separate variable:
proc format;
value $x 'A'='One'
'B'='Two';
run;
data have;
input x $;
format x $x.;
datalines;
A
B
;
data want;
set have(rename=(x=xRaw)); /* rename the raw data */
length x $3; /* =max length of formmatted values */
x = put(xRaw, $x.); /* new var w/ formatted values */
run;
proc iml;
call ExportDataSetToR("want","wantInR");
submit / R;
wantInR
endsubmit;
quit;
As always, thank you Rick
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.