JPC
JPC

Reputation: 5183

How to get sas date format "YYYYMM"

How to get sas date format "YYYYMM" in SAS ?

From this code below I would get '2011-11-01'

call symput('me',"'"||put(intnx('month',today(),-1 ),yymmdd10.)||"'");

I'm trying to get something like : '2011-11'

Thanks

Upvotes: 4

Views: 46491

Answers (4)

usct01
usct01

Reputation: 898

mydate = put(date, YYMMD7.)

See this for details.

Upvotes: 0

Jonas Tundo
Jonas Tundo

Reputation: 6207

For more information on formats visit http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002231336.htm

You can use one of the examples or "create" your own.

For example:

data datum;
datum=date();
datum1mback= INTNX( 'month', datum, -1); 
format datum1mback yymmn6.; /* returns 201111 (if we consider the date of the question of course) */
run; 

/* yymmp6. returns 11.11 */
/* yymmc8. returns 2011:11 */
/*...*/

Upvotes: -1

Robert Penridge
Robert Penridge

Reputation: 8513

Macro version:

%let date = %sysfunc(today());
%let me = %str(%")%sysfunc(intnx(month,&date,-1),yymmd7.)%str(%");

%put &me;

Upvotes: 5

Robbie Liu
Robbie Liu

Reputation: 1511

You can replace yymmdd10. with yymmd7. that should be the format you want.

Upvotes: 5

Related Questions