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

I'm working on a template that may have on the xaxes either an integer that is a count of months, or a SAS date.

 

I need different options for these.

 

I had hoped I could put both my LINEAROPTS and my TIMEOPTS on the same COLUMNAXIS statement thinking that SGRENDER would pick the ones that make sense and ignore the other.  Didn't work out.

 

I know my SAS dates have a MONYY type format, so I turned to conditional logic like follows:

 

if (vformatn(_X) = "MONYY")

      columnaxes;

      columnaxis / griddisplay=on timeopts=(minorgrid=true minorticks=true minortickinterval=month);

   endcolumnaxes;

else

      columnaxes;

      columnaxis / griddisplay=on linearopts=(minorgrid=true);

   endcolumnaxes;

endif;/*sas date or not*/

 

But this isn't working as expected.  If I pass a linear value for _X it's fine, but if I pass a SAS date I don't get my axes options and I'm struggling to figure out why. 

 

Thanks (SAS 9.4 M3)

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

From the GTL documentation:

SAS functions that can be used in a WHERE expression include

  • character handling functions
  • date and time functions
  • mathematical and statistical functions.

Note: Not all SAS functions are available in WHERE expressions. Call routines and other DATA-step-only functions (for example, LAG, VNAME, OPEN) are some examples of functions that cannot be used.

 

Since they explicitly state VNAME isn't available I would extend that to all of the variable information functions. So make the value a parameter that can be passed to the GTL.

I suspect that you were getting things to work for the "numeric" values as the compare always failed and the else behavior kicked in. Did you look for any notes in the log when the template was compiled?

View solution in original post

3 REPLIES 3
ANWZimmerman
Obsidian | Level 7

Oh, it wasn't super clear to me if I wanted FORMATN or FORMATNX so I tried both, neither worked.

ballardw
Super User

From the GTL documentation:

SAS functions that can be used in a WHERE expression include

  • character handling functions
  • date and time functions
  • mathematical and statistical functions.

Note: Not all SAS functions are available in WHERE expressions. Call routines and other DATA-step-only functions (for example, LAG, VNAME, OPEN) are some examples of functions that cannot be used.

 

Since they explicitly state VNAME isn't available I would extend that to all of the variable information functions. So make the value a parameter that can be passed to the GTL.

I suspect that you were getting things to work for the "numeric" values as the compare always failed and the else behavior kicked in. Did you look for any notes in the log when the template was compiled?

ANWZimmerman
Obsidian | Level 7

That was the problem.  I missed that.  So my solution was to add this to my code:

 

data _NULL_;

set &dsn;

call symput('xform',(vformatn(&x)));

run;

 

Then I can pass the value of &xform into GTL for the conditional logic and now it works perfectly!

 

Thanks

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!

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