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

Hello,

 

I guess I'm hoping there's someone who might know of some updated solution/workaround to the already-documented issue of user-defined picture formats not rendering in proc sgplot.

 

I am using picture formats to generate a Mon-YY format with a dash, courtesy of another kind user: https://communities.sas.com/t5/General-SAS-Programming/MONTH-YY-and-MON-YY-date-format/m-p/446015/hi...

 

Realized after accepting the solution that they won't render in proc sgplot. Like the user in the first link above, I can't format the dataset outside and then plot that discretely (as suggested) because I'm using a slightly tricky time axis, was difficult enough to get it to do what I want without introducing the formatting issue:

		xaxis display=(nolabel) type= time notimesplit fitpolicy= rotate interval= semiyear values= ('01JAN2000'd to &today. by semiyear)  valuesformat= MONYY5.;



Currently I'm using MONYY5., but I would like to get Mon-YY if possible.

Would appreciate any insight if anyone has any.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
DR_Majeti
Quartz | Level 8

Please try like below, 

 

I have created small example data. 

 

 

data simple ;
do x= '01jan2018'd to '31dec2018'd by 30;
y+1;
output;
end;
run;

data fmt;
set simple;
start=x;
label=strip(substr(put(start,monyy5.),1,3))||'-'||strip(put(year(x),best.));
fmtname='chkfmt';
run;

proc format cntlin=fmt;
run;

proc sgplot data=simple;
scatter x=x y=y ;
xaxis label=' SAS defined format' ;
format x monyy7. ;
run;


proc sgplot data=simple;
scatter x=x y=y ;
xaxis label=' User defined format' values=('01jan2018'd to '31dec2018'd by 30);
format x chkfmt. ;
run;

View solution in original post

19 REPLIES 19
Reeza
Super User

What version of SAS are you using?

Proc product_status;run;
DanH_sas
SAS Super FREQ

What you could do is use a small data step to create a column of formatted month values. Then, use that dataset with SGPLOT, referencing that formatted variable for your category values.

 

Hope this helps!

Dan

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Thanks for your response! 

I think this might be the same issue where if I format it beforehand, I won't be able to plot it on the time type x-axis since it won't be a sasdate anymore?

ballardw
Super User

Some example data and your current sgplot code might go a ways towards a solution. Especially if you can describe what is wrong with axis appearance.

 

I don't think I would consider that a "tricky" axis though.

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Thanks for your response!
Yeah, I guess I meant "tricky" relative to other datasets that I easily changed to a discrete axis for. 

I am trying to automate in SAS a graph produced by my organization. I basically have a dataset with a value for every month since, say, Jan 2000 until Dec 2017. I want my x axis values to be every 6 months starting with a month I choose, e.g. Feb-01 Aug-01 Feb-02 Aug-02 etc, with a line marker for every month's observation, not just Feb and Aug.  I was able to establish this with the time type x-axis statement above after some trial and error (I am new to graphing in SAS hence it was tricky) but it doesn't give me the Mon-YY formatting I want. 

I can get the Mon-YY formatting I want if I drop all but Feb and Aug observations from my dataset, apply the user-defined format, and then plot discretely. But then I will lose the line-markers for non-Feb/Aug months.

It's not such a big deal, but since I'm trying to replicate exactly what the organization already does and since it seems like it should be doable, I want to see if I can get both Mon-YY formatting as well as markers for every month (mutually exclusive in my trials so far). But again, not a big deal if it's not possible.

Sample data would just be one record for every month from, say, Jan 2000 until Dec 2017, where month is formatted as date9 and value can be anything. I'm trying to be cautious about what I share or else I would put something here.

Thanks very much!

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Sorry, forgot to include my sgplot code:

      proc sgplot data= temp.figure noborder nowall pad=(left= 5pct right= 5pct) noautolegend;
           series x= month y= change/ lineattrs= (color= black thickness = 2) markers markerattrs= (symbol= diamondfilled color= darkblue);
           xaxis display=(nolabel) type= time notimesplit fitpolicy= rotate interval= semiyear values= ('01FEB2000'd to &today. by semiyear) valuesformat= MONYY5. valueattrs= (family= albany size= 12px weight=bold) offsetmin= 0 offsetmax= 0;
           yaxis label= 'Label' labelattrs= (family= albany weight= bold size= 9.5pt) valueattrs= (family= albany weight=bold) values= (-0.28 to 0.16 by 0.02) valuesformat= PERCENTN10.1;
           band x= month upper= 0.15 lower= -0.23 / fillattrs= (color= aliceblue) transparency= 0.5; 
           refline 0 / lineattrs=(color=LIGB);
      run;
DR_Majeti
Quartz | Level 8

Hi,

 

Please try to use FORMAT statement in the proc sgplot. 

 

Ex: Format xaxisvariable MONYY5./predefined format created ;

 

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Thanks for your response!

Tried this out (removing the valuesformat= option on the xaxis statement), it gives the same issue. The user-generated format doesn't load, showing only '0B-%0y'.

DR_Majeti
Quartz | Level 8

Please try like below, 

 

I have created small example data. 

 

 

data simple ;
do x= '01jan2018'd to '31dec2018'd by 30;
y+1;
output;
end;
run;

data fmt;
set simple;
start=x;
label=strip(substr(put(start,monyy5.),1,3))||'-'||strip(put(year(x),best.));
fmtname='chkfmt';
run;

proc format cntlin=fmt;
run;

proc sgplot data=simple;
scatter x=x y=y ;
xaxis label=' SAS defined format' ;
format x monyy7. ;
run;


proc sgplot data=simple;
scatter x=x y=y ;
xaxis label=' User defined format' values=('01jan2018'd to '31dec2018'd by 30);
format x chkfmt. ;
run;

Reeza
Super User

@DR_Majeti is correct. A PICTURE format will not work, but using a 'normal' format seems to work. That's an important distinction and good to know, learn something new every day!

 

 

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Am checking this out, will update here soon. Thank you!!

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Worked! Cat Very Happy

Instead of using it through a separate format statement I used it with the "valuesformat=" option on the xaxis statement - the former caused my axis to change from semi-yearly to yearly, for some reason. Using it with valuesformat works perfectly.

Thank you very, very much.

Reeza
Super User

It is noted in the documentation that SAS custom formats do not work in GTL, so unfortunately the format you want isn't available. 

 

You're likely correct in that converting the date will not give you what you want, but I'd try it to verify anyways.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 19 replies
  • 3720 views
  • 10 likes
  • 7 in conversation