BookmarkSubscribeRSS Feed
linlin87
Quartz | Level 8

Hi SAS Users,

Please help to me. I have question with datetime variable. I have problem:

proc sgplot data=temp_by_country;
by country;
scatter x=datetime y=temp / markerattrs=(size=3pt symbol=circle) group=district;
/* xaxis min=start max=end; */
run;

I am plotting temperature as a function of datetime, creating plot for each country. I want plot to extend beyond datetime for each country, by a specific amount for each country.

 

Therefore I want set the max and min of by group (comment out bit above) from a VARIABLE not a numeric-value.

How can I do?

Thank you for help!

1 REPLY 1
ballardw
Super User

What you request is not an option in SGPLOT Xaxis statement at this time. IF you provide a single values of max= and min= then all axis generated by SGPLOT would have the same limits.

 

Your options appear to be limited to multiple SGPLOT calls similar to

proc sgplot data=temp_by_country;
Where country="country1 name";
scatter x=datetime y=temp / markerattrs=(size=3pt symbol=circle) group=district;
 xaxis min=<start value for country1> max=<end value for country1>; 
run;

If you have a data set that has just the country name (or code or whatever) and the min and max values you could use a data step with CALL EXECUTE statements to generate code similar to the above. Or use the data step to write program code and call the program with %include.

A limited example as I have no idea what any of your data or even the limits that you want might be:

data limits;
   input countryname $ min max;
datalines;
AAAA  1234  78910
BBBB  1111  88888
;

data _null_;
   set limits;
   file print;
   length longstr $200.;
   put "proc sgplot data=temp_by_country;";
   longstr = cats("where country=",quote(strip(countryname)),";");
   put longstr;
   put "scatter x=datetime y=temp / markerattrs=(size=3pt symbol=circle) group=district;";
   longstr=catt("xaxis min=",min," max=",max,';');
   put longstr;
   put "run;";
run;

The first data set is just to have limits somewhere. The second data step will write code to the results window. Depending on your session long lines may get wrapped. If you don't generate real long lines you would replace the File Print , which is what sends text to the results window, with the path and name of a file such as: File "C:\somefolder\mysgplotcode.sas";

Then use %include "C:\somefolder\mysgplotcode.sas"; to call the code and execute it.

OR every place that the second data set has a PUT replace it with Call Execute (<the string to write goes here>);

Call execute stacks statements into the execution buffer and runs after the data step completes.

I would suggest using the write to file approach so you can see that the created text is correct.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 442 views
  • 2 likes
  • 2 in conversation