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

Is there a way to use a sas function in a proc sgplot statement?

I would like to test many different transformations and it would be nice not having to add new colums to the data each time.

 

I tried within a macro and different versions of %sysfunc(nput(sqrt(Systolic,8.8))) but got different errors each time.

 

proc sgplot data=sashelp.heart;
loess x=Diastolic y=sqrt(Systolic);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

PROC SGPLOT works with columns in a data set, and not with functions of columns, so what you are requesting is not possible.

 


@SarahDew wrote:

 

I tried within a macro and different versions of %sysfunc(nput(sqrt(Systolic,8.8))) but got different errors each time.


Also, %sysfunc cannot access data set variables such as systolic, it works on macro variables, so that won't work either.

 

Instead of plotting many transformations of the Y variable, you could do a Box-Cox transformation which will pick the "best" transformation of the Y variable. https://documentation.sas.com/doc/en/pgmsascdc/v_023/statug/statug_transreg_details02.htm Note: these transformations find the best transformation to make the Y-variable as close as possible to being normally distributed, which may or may no tbe what you want. Also, PROC TRANSREG allows you to fit different transformations of the Y variable to see how well the model fits, without creating new variables in a DATA step, as you are tying to do.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

PROC SGPLOT works with columns in a data set, and not with functions of columns, so what you are requesting is not possible.

 


@SarahDew wrote:

 

I tried within a macro and different versions of %sysfunc(nput(sqrt(Systolic,8.8))) but got different errors each time.


Also, %sysfunc cannot access data set variables such as systolic, it works on macro variables, so that won't work either.

 

Instead of plotting many transformations of the Y variable, you could do a Box-Cox transformation which will pick the "best" transformation of the Y variable. https://documentation.sas.com/doc/en/pgmsascdc/v_023/statug/statug_transreg_details02.htm Note: these transformations find the best transformation to make the Y-variable as close as possible to being normally distributed, which may or may no tbe what you want. Also, PROC TRANSREG allows you to fit different transformations of the Y variable to see how well the model fits, without creating new variables in a DATA step, as you are tying to do.

--
Paige Miller
Rick_SAS
SAS Super FREQ

If you use a DATA step view, you don't need to add columns. Instead, you add a formula that gets evaluated when needed, which seems to be what you want. For example,

data Heart / view=Heart;                 /* define DATA step view */
   set Sashelp.Heart;
   SqrtSystolic = sqrt(Systolic);
   LogSystolic = Log(Systolic);
   RecipSystolic = 1 / Systolic;
run;

ods graphics / loessmaxobs=100000;
proc sgplot data=Heart;
loess x=Diastolic y=SqrtSystolic;
run;
ballardw
Super User

An approach that may be more work than it is worth would be to create custom Formats. You can create formats that will use functions generated by the FCMP procedure. There is an example in the Proc Format documentation "Creating a function to use as a Format" that demonstrates writing a format to display temperature data converted to/from Fahrenheit to Celsius.

 

The caveat I throw out is learning an entire new procedure, FCMP, and the differences, minor but present, from data step coding and then Proc Format. Depending on the exact transform you may spend a lot time getting that to work. You also then get keep changing the format in the Proc SGplot and you really should include something to read in the output to make sure you know which is used when.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 400 views
  • 2 likes
  • 4 in conversation