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

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
Obsidian | Level 7

As always, thank you Rick

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 535 views
  • 0 likes
  • 2 in conversation