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

Hi Please let me know how below plot genrated in sas by using proc sgplot with higlow veritical procedure 

 

The Y axis need display the Months of duarion

The X axis will be subejcts

 

The data like below:

 

data indata:
input subject $100 startdt date9. enddt date9. ;
datalines;
1001 08Jan2108 09Dec2020
1002 10Feb2019 10Jan2021
1003  20Mar2019 12Mar2021
1004  27Feb202  13Nov2021
1005  01Mar2018  15Aug200
1006  23Feb2019 28Jun2021
1007  18Apr2018 12Jul2020
1009  17Mar2019  20Oct2020
1010   12Sep2018  13Jan2019
;
run;

Output plot :

raja777pharma_0-1636608986539.png

 

Thank you,

Rajasekhar

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Here could give you a start.

Ksharp_0-1636803373639.png

 

 

data indata;
input subject  startdt : date9. enddt : date9. ;
format startdt enddt date9.;
datalines;
1001 08Jan2018 09Dec2020
1002 10Feb2019 10Jan2021
1003  20Mar2019 12Mar2021
1004  27Feb2019  13Nov2021
1005  01Mar2018  15Aug2021
1006  23Feb2019 28Jun2021
1007  18Apr2018 12Jul2020
1009  17Mar2019  20Oct2020
1010  12Sep2018  13Jan2019
;
run;
proc sort data=indata;
  by descending startdt;
run;
proc summary data=indata;
var startdt enddt subject;
output out=min_max min(startdt)=min max(enddt)=max ;
run;
data want;
 set indata;
 if _n_=1 then do;
   set min_max;
   mean=1010;_mean=1007;
   high1='01jan2020'd;mean1=mean(min,'01jan2020'd);text1='78% subject';
   high2='01jan2020'd;mean2=mean('01jan2020'd,max);text2='22% subject';  
 end;
  else call missing(min,max,mean);
run;

proc sgplot data=want noautolegend;
highlow y=subject low=startdt high=enddt;

highlow y=mean low=min high=high1/highcap=filledarrow lowcap=filledarrow lineattrs=(pattern=dash color=red thickness=4);
text y=_mean x=mean1 text=text1/strip CONTRIBUTEOFFSETS=none textattrs=(size=20 color=red);

highlow y=mean low=high2 high=max/highcap=filledarrow lowcap=filledarrow lineattrs=(pattern=dash color=red thickness=4);
text y=_mean x=mean2 text=text2/strip CONTRIBUTEOFFSETS=none textattrs=(size=20 color=red);

xaxis  valuesformat=date9. label=' ';
refline '01jan2020'd /axis=x label='JAN 2020' lineattrs=(pattern=dash color=red thickness=4);
yaxis type=discrete discreteorder=data  label=' ';
run;

 

View solution in original post

4 REPLIES 4
Ksharp
Super User

This could get you a start.

 

data indata;
input subject  startdt : date9. enddt : date9. ;
format startdt enddt date9.;
datalines;
1001 08Jan2108 09Dec2020
1002 10Feb2019 10Jan2021
1003  20Mar2019 12Mar2021
1004  27Feb2019  13Nov2021
1005  01Mar2018  15Aug2021
1006  23Feb2019 28Jun2021
1007  18Apr2018 12Jul2020
1009  17Mar2019  20Oct2020
1010  12Sep2018  13Jan2019
;
run;

proc sgplot data=indata;
highlow y=subject low=startdt high=enddt;
xaxis  valuesformat=date9. max='20aug2021'd;
refline '01jan2020'd /axis=x label ;
run;
ballardw
Super User

Steeling heavily from @Ksharp but 1) fixing the data in the first row where the Start is way after the End date,

Adding a sort and Yaxis to get the data into a similar shape as the requested graph:


data indata;
input subject  startdt : date9. enddt : date9. ;
format startdt enddt date9.;
datalines;
1001 08Jan2018 09Dec2020
1002 10Feb2019 10Jan2021
1003  20Mar2019 12Mar2021
1004  27Feb2019  13Nov2021
1005  01Mar2018  15Aug2021
1006  23Feb2019 28Jun2021
1007  18Apr2018 12Jul2020
1009  17Mar2019  20Oct2020
1010  12Sep2018  13Jan2019
;
run;
proc sort data=indata;
  by descending startdt;
run;
proc sgplot data=indata;
highlow y=subject low=startdt high=enddt;
xaxis  valuesformat=date9. max='20aug2021'd;
refline '01jan2020'd /axis=x label='JAN 2020' ;
yaxis type=discrete discreteorder=data ;
run;

The Sort by Descending is because the graph wants to know which value goes closest to the Xaxis first and builds away from the axis. So you want the largest Start value first to appear at the bottom. This works with the Yaxis optionsType and Discreteorder=data to get the data into the apparently desired order.

raja777pharma
Fluorite | Level 6

Hi ,

 

Thak you for provuding coding details.

 

Just want know how to anotate graph (insert the text inside the label as per below).

 

raja777pharma_1-1636724496230.png

 

 

I am using below code.

 

raja777pharma_0-1636724371751.png

 

Thank you,

Rajasekhar

Ksharp
Super User

Here could give you a start.

Ksharp_0-1636803373639.png

 

 

data indata;
input subject  startdt : date9. enddt : date9. ;
format startdt enddt date9.;
datalines;
1001 08Jan2018 09Dec2020
1002 10Feb2019 10Jan2021
1003  20Mar2019 12Mar2021
1004  27Feb2019  13Nov2021
1005  01Mar2018  15Aug2021
1006  23Feb2019 28Jun2021
1007  18Apr2018 12Jul2020
1009  17Mar2019  20Oct2020
1010  12Sep2018  13Jan2019
;
run;
proc sort data=indata;
  by descending startdt;
run;
proc summary data=indata;
var startdt enddt subject;
output out=min_max min(startdt)=min max(enddt)=max ;
run;
data want;
 set indata;
 if _n_=1 then do;
   set min_max;
   mean=1010;_mean=1007;
   high1='01jan2020'd;mean1=mean(min,'01jan2020'd);text1='78% subject';
   high2='01jan2020'd;mean2=mean('01jan2020'd,max);text2='22% subject';  
 end;
  else call missing(min,max,mean);
run;

proc sgplot data=want noautolegend;
highlow y=subject low=startdt high=enddt;

highlow y=mean low=min high=high1/highcap=filledarrow lowcap=filledarrow lineattrs=(pattern=dash color=red thickness=4);
text y=_mean x=mean1 text=text1/strip CONTRIBUTEOFFSETS=none textattrs=(size=20 color=red);

highlow y=mean low=high2 high=max/highcap=filledarrow lowcap=filledarrow lineattrs=(pattern=dash color=red thickness=4);
text y=_mean x=mean2 text=text2/strip CONTRIBUTEOFFSETS=none textattrs=(size=20 color=red);

xaxis  valuesformat=date9. label=' ';
refline '01jan2020'd /axis=x label='JAN 2020' lineattrs=(pattern=dash color=red thickness=4);
yaxis type=discrete discreteorder=data  label=' ';
run;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 917 views
  • 2 likes
  • 3 in conversation