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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

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;
spirto
Quartz | Level 8

As always, thank you Rick

SAS Innovate 2025: Register Now

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!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 794 views
  • 0 likes
  • 2 in conversation