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

I have the following data.

I want to plot the pct_change(on y axis) and yyyymm (on x axis).

Also, is there a way to add 2 reference lines?

%let lower_reference_line=-0.5;
%let upper_reference_line= 0.5;

data temp; infile datalines missover dsd dlm=" "; input yyyymm pct_change; informat yyyymm yymmdd10. pct_change percent10.2; format yyyymm yymmdd10. pct_change percent10.2; datalines; 2020-05-01 0.74% 2020-06-01 0.84% 2020-07-01 0.67% 2020-08-01 0.52% 2020-09-01 0.56% 2020-10-01 0.50% 2020-11-01 0.37% 2020-12-01 1.07% 2021-01-01 0.38% 2021-02-01 0.34% 2021-03-01 0.63% 2021-04-01 0.80% 2021-05-01 0.71% ;run;

I tried a couple of things but the layout of X-axis is weird.

 

Please advise.

 

Thank You.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Where do you want the reference lines? Which direction would they run?

When dealing with dates on an axis you may have to sort the data by the date variable to get a better graph. Your example data doesn't show anything weird on the xaxis. SAS will attempt to make "nice" tickmarks based on the range of values if you do not provide an XAXIS statement to set the properties. Your example data covers a period of a year so shows one tick for each month and the year where it changes.

 

This places a reference line at the .5% line in a graph.

proc sgplot data=temp;
   series x=yyyymm y=pct_change ;
   /* horizontal reference line at .5%*/
   refline  .005 ;
   yaxis values=(0 to .02 by 0.005);
run;

Your values in the macro variables would be WAY out of range for the given percentages you show. 0.5 = 50%.

So a clearer description of where, in relation to the data values you expect these reference lines to appear is needed.

 

Or did you want to show a some sort of band around the generated series line? That would require adding some variables to your data to indicate the upper/lower bounds at each point. But again, .5 is likely to be right out as an actual offset.

View solution in original post

4 REPLIES 4
djrisks
Barite | Level 11

Hello,

 

You can try this code. You need to remember to divide the refline by 100 too, hence 0.005 should be used.

 

proc sgplot data = temp;
  series x = yyyymm y = pct_change;
  refline 0.005 /axis = y;
run;

Thanks

 

SGPlot19.png

Reeza
Super User
To add multiple reference lines add more REFLINE statements.
ballardw
Super User

Where do you want the reference lines? Which direction would they run?

When dealing with dates on an axis you may have to sort the data by the date variable to get a better graph. Your example data doesn't show anything weird on the xaxis. SAS will attempt to make "nice" tickmarks based on the range of values if you do not provide an XAXIS statement to set the properties. Your example data covers a period of a year so shows one tick for each month and the year where it changes.

 

This places a reference line at the .5% line in a graph.

proc sgplot data=temp;
   series x=yyyymm y=pct_change ;
   /* horizontal reference line at .5%*/
   refline  .005 ;
   yaxis values=(0 to .02 by 0.005);
run;

Your values in the macro variables would be WAY out of range for the given percentages you show. 0.5 = 50%.

So a clearer description of where, in relation to the data values you expect these reference lines to appear is needed.

 

Or did you want to show a some sort of band around the generated series line? That would require adding some variables to your data to indicate the upper/lower bounds at each point. But again, .5 is likely to be right out as an actual offset.

david27
Quartz | Level 8

 Thank You @ballardw @Reeza and @djrisks  for your help.

 

Regards

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1471 views
  • 7 likes
  • 4 in conversation