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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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