BookmarkSubscribeRSS Feed
mduarte
Quartz | Level 8

Hi - I am trying to add a refline at each year between a minimum and maximum date, with no success.  Code to date is as follows:

 

%LET date1 = '01Jan2015';  
%LET date2 = '01Jan2018'; 

data test;
	date= &date1.d;
	do while(date <= &date2.d);
		y = rand('NORMAL', 0, 1);
		output;
		date=intnx('month', date, 1, 's');
	end;
	format date yymmdd10.;
  run;

proc print data=test(obs=5);
run;

proc sgplot data=test;
   series x=date y=y /markers;
   refline &date1.d / axis=x lineattrs=(color=red);
   *refline (&date1.d to &date2.d by month) / axis=x lineattrs=(color=red);
run;

Any help would be greatly appreciated.

 

Thanks.

2 REPLIES 2
Jay54
Meteorite | Level 14

You need to use a data set variable for the REFLINE statement.  In the program below, I have computed a new one called Date2 in the data step to demonstrate the usage.

 

proc sgplot data=test;
  series x=date y=y /markers;
  refline date2/ axis=x lineattrs=(color=red);
run;

 

Dateref.png

 

 

%LET date1 = '01Jan2015';
%LET date2 = '01Jan2018';

data test;
date= &date1.d;
do while(date <= &date2.d);
date2=.;
y = rand('NORMAL', 0, 1);
if date >= '01jan2016'd and date <= '01Jan2017'd then date2=date;
output;
date=intnx('month', date, 1, 's');
end;
format date date2 yymmdd10.;
run;

proc print data=test;
run;

proc sgplot data=test;
series x=date y=y /markers;
refline date2/ axis=x lineattrs=(color=red);
*refline (&date1.d to &date2.d by month) / axis=x lineattrs=(color=red);
run;

mduarte
Quartz | Level 8

Hi @Jay54.  Thanks for the suggestion although I am not sure it will work in this case.  Firstly, my data already exists (the data I created in the post was just to make the example reproducible) and it is not certain that a data point will exist on each year.

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