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

Is there a way to format date in the abbreviated month-year format that will work in English and French?

 

I am creating a bilingual English-French report with tables and graphs. I have to show the date in mmmyy  format.    I can get this using  the format monyy.   This works in English, so for French I used the fr-CA locale.  I specified the NLDATEYM format which is equivalent to monyy according to the SAS manual.  I need to keep the date field as numeric so it displays properly on a graph axis.

 

However, NLDATEYM does not give the abbreviated month name (as shown in the second table).

 

Therefore I created a new variable  (newdate) using the NLDATE function as in the dataset new in the code attached.  Unfortunately it creates a character value that does not really work in the graph.

 

 I am using SAS 9.4 (release 3)

Capture.JPGoption missing='-' locale='en_US'; 

data stocks;
   set sashelp.stocks (where=(year(date)=2005));
run;  
proc sort;  
by descending stock date;
run;

proc report nowd;
Title "locale='en_US'";
   format date monyy.;
   column stock close,date;
   define stock/group order=data;   
   define close/analysis ' ' ;
   define date/across ' ' order=data;
 run;
 
 option locale='fr_CA';
proc report nowd;
Title "locale='fr_CA'";
   format date NLDATEYM.;
   column stock close,date;
   define stock/group order=data;   
   define close/analysis ' ' ;
   define date/across ' ' order=data;
 run;
 
data new;
   set stocks;    
      newdate=nldate(date,'%b%y');
run;
 proc report nowd;
Title "locale='fr_CA' with newdate=nldate(date,'%b%y')";
   column stock close,newdate;
   define stock/group order=data; 
   define close/analysis ' ' ;
   define newdate/across ' ' order=data;  
 run;
 
 title '';
proc sgplot data=new(where=(stock='IBM')) noborder;
  vbar newdate / response=close  
           group=stock;
  xaxis display=(nolabel noline noticks);
  yaxis display=(noline noticks) grid;
run;
 

Any help to solve this issue will be greatly appreciated.

Thanks  

1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11

Found the answer from SAS Tech Support. 

 

The line that did the trick is the following format statement, works for both English and French locale in Report and SGPLOT:

 

format date EURDFMY. ;

 

Thanks everyone for taking the time to help.

 

 

View solution in original post

15 REPLIES 15
ChrisNZ
Tourmaline | Level 20

Why not 

proc sgplot data=stocks(where=(stock='IBM')) noborder;
   format date NLDATEYM.;
  vbar date / response=close  
           group=stock;
  xaxis display=(nolabel noline noticks);
  yaxis display=(noline noticks) grid;
run;
I

It works fine for the graph

Capture.PNG

 

 

ghosh
Barite | Level 11

>Thanks for your response.  However, as I mentioned, I would like to use abbreviated month names.

Oops sorry, mmm more thinking required!

 

ChrisNZ
Tourmaline | Level 20

I tried

proc format; 
  picture moisyy (default=5)
    low - high = '%b%Y' (datatype=date)  ;
run; 

but the locale is ignored.

 

ballardw
Super User

@ghosh wrote:

>Thanks for your response.  However, as I mentioned, I would like to use abbreviated month names.

Oops sorry, mmm more thinking required!

 


You did not specify a width for the NLDATEYM format. When you just NLDATEYM the default width is 16. Specify NLDATEYM6. to get something such as OCT 14 (Month and 2 digit year).

ghosh
Barite | Level 11
NLDATEYM6. does not work, shows asterisks for just one period.
PGStats
Opal | Level 21

How about

 

proc sgplot data=sashelp.stocks(where=(stock='IBM' and year(date)=2000)) noborder;
   format date NLDATEYMM.;
  vbar date / response=close  
           group=stock;
  xaxis display=(nolabel noline noticks);
  yaxis display=(noline noticks) grid;
run;

SGPlot2.png

PG
ghosh
Barite | Level 11

That's very close, is it possible to show just the last two digits of the year, all in one row?

Thanks for the suggestion, though!

Tom
Super User Tom
Super User

Why not just use the month number instead?  YYMMD7.

431   data _null_;
432     do month=1 to 12;
433       date=mdy(month,1,2018);
434       put month= date= yymmd7. ;
435     end;
436   run;

month=1 date=2018-01
month=2 date=2018-02
month=3 date=2018-03
month=4 date=2018-04
month=5 date=2018-05
month=6 date=2018-06
month=7 date=2018-07
month=8 date=2018-08
month=9 date=2018-09
month=10 date=2018-10
month=11 date=2018-11
month=12 date=2018-12

 

ghosh
Barite | Level 11

Hi Tom, The specifications require it in that format.

Thanks!

Tom
Super User Tom
Super User

Worked for me.

 

4     %put locale=%sysfunc(getoption(locale));
locale=FRENCH_FRANCE
5     proc format ;
6       picture my low-high='%b-%Y' (datatype=date);
NOTE: Format MY has been output.
7     run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


8
9     data xx ;
10     do month=1 to 12;
11       date=mdy(month,1,2019);
12       str=put(date,my8.);
13       put (_all_) (=);
14     end;
15    run;

month=1 date=21550 str=jan-2019
month=2 date=21581 str=fev-2019
month=3 date=21609 str=mar-2019
month=4 date=21640 str=avr-2019
month=5 date=21670 str=mai-2019
month=6 date=21701 str=jun-2019
month=7 date=21731 str=jul-2019
month=8 date=21762 str=aou-2019
month=9 date=21793 str=sep-2019
month=10 date=21823 str=oct-2019
month=11 date=21854 str=nov-2019
month=12 date=21884 str=dec-2019
NOTE: The data set WORK.XX has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.16 seconds
      cpu time            0.01 seconds


16    options locale=English;
17    %put locale=%sysfunc(getoption(locale));
locale=ENGLISH_UNITEDSTATES
18    data xx ;
19     do month=1 to 12;
20       date=mdy(month,1,2019);
21       str=put(date,my8.);
22       put (_all_) (=);
23     end;
24    run;

month=1 date=21550 str=JAN-2019
month=2 date=21581 str=FEB-2019
month=3 date=21609 str=MAR-2019
month=4 date=21640 str=APR-2019
month=5 date=21670 str=MAY-2019
month=6 date=21701 str=JUN-2019
month=7 date=21731 str=JUL-2019
month=8 date=21762 str=AUG-2019
month=9 date=21793 str=SEP-2019
month=10 date=21823 str=OCT-2019
month=11 date=21854 str=NOV-2019
month=12 date=21884 str=DEC-2019
NOTE: The data set WORK.XX has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

ghosh
Barite | Level 11

Tom, when I tried the Picture format earlier, it did not work with SGPLOT.  btw %b%y (lowercase gives 2 digit year) would be perfect.

I will try with your code first thing tomorrow morning.

Thanks!

ghosh
Barite | Level 11

The picture format does not work with SGPLOT or Proc Report

 

Capture.JPG

option missing='-' locale='en_US'; 
data stocks;
   set sashelp.stocks (where=(year(date)=2005));
run;  
proc sort;  
by descending stock date;
run;

proc format;
  picture my low - high= '%b%y' (datatype=date);
  run;

proc report nowd;
Title "locale='en_US'";
   format date my.;
   column stock close,date;
   define stock/group order=data;   
   define close/analysis ' ' ;
   define date/across ' ' order=data;
 run;

proc sgplot data=stocks(where=(stock='IBM')) noborder;
   format date my.;
  vbar date / response=close  
           group=stock;
  xaxis display=(nolabel noline noticks);
  yaxis display=(noline noticks) grid;
run;
 
option missing='-' locale='fr_CA';
proc report nowd;
Title "locale='fr_CA'";
   format date my.;
   column stock close,date;
   define stock/group order=data;   
   define close/analysis ' ' ;
   define date/across ' ' order=data;
 run;

proc sgplot data=stocks(where=(stock='IBM')) noborder;
   format date my.;
  vbar date / response=close  
           group=stock;
  xaxis display=(nolabel noline noticks);
  yaxis display=(noline noticks) grid;
run;
 
ghosh
Barite | Level 11

Found the answer from SAS Tech Support. 

 

The line that did the trick is the following format statement, works for both English and French locale in Report and SGPLOT:

 

format date EURDFMY. ;

 

Thanks everyone for taking the time to help.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 15 replies
  • 4373 views
  • 2 likes
  • 5 in conversation