Discussion:
DATE FORMATING
(too old to reply)
r***@gmail.com
2008-01-02 15:18:14 UTC
Permalink
I need previous month date and year in a macro variable in mmyy form

Ex: 1
Todays date is 01/02/08
01 is month and 08 is year I need value of previous month

Mm= 12 will be previous month value
YR= 07 the year corresponding to that month

I need 1207 value

Ex2:

If Date in 1st feb 08

I need 0108 value // prev month would be JAN ie 01 and year would be
same so 08


I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
a***@bigfoot.com
2008-01-02 15:45:29 UTC
Permalink
Use the INTNX function to calculate the date value you want.
Format the resulting value using mmyyn4. format.

data;
lastmonth = intnx('month', date(), -1);
format lastmonth mmyyn4.;
run;
________________________________________________________

INTNX Function
Increments a date, time, or datetime value by a given interval or
intervals, and returns a date, time, or datetime value
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000212700.htm

MMYYxw. Format
Writes date values in the form mm<yy>yy or mmX<yy>yy, where X
represents a specified separator and the year appears as either 2 or 4
digits (N indicates no separator)
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a002231365.htm
________________________________________________________

http://support.sas.com/onlinedoc/913/docMainpage.jsp

Base SAS
SAS Language Reference: Concepts
Dates, Times, and Intervals
http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a001112342.htm

Dictionary of Language Elements
Functions and CALL Routines
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000245852.htm
Post by r***@gmail.com
I need previous month date and year in a macro variable in mmyy form
Ex: 1
Todays date is 01/02/08
01 is month and 08 is year  I need value of previous month
Mm= 12 will be previous month value
YR=   07 the year corresponding to that month
I need  1207 value
If Date in 1st feb 08
I need 0108 value  // prev month would be JAN ie 01 and year would be
same so 08
I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
Jack Clark
2008-01-02 15:40:09 UTC
Permalink
You can use the INTNX function to adjust today's date (or any SAS date
variable) by -1 months, then put the resulting date in MMYY format with
a PUT function and the MMYYN4. format. CALL SYMPUT will load the
resulting value into a macro variable.


data _null_;
call symput('newvar',put(intnx('MONTH',today(),-1),mmyyn4.));
run;

%put &newvar;


Jack Clark
Research Analyst
Center for Health Program Development and Management
University of Maryland, Baltimore County

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@gmail.com
Sent: Wednesday, January 02, 2008 10:18 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: DATE FORMATING

I need previous month date and year in a macro variable in mmyy form

Ex: 1
Todays date is 01/02/08
01 is month and 08 is year I need value of previous month

Mm= 12 will be previous month value
YR= 07 the year corresponding to that month

I need 1207 value

Ex2:

If Date in 1st feb 08

I need 0108 value // prev month would be JAN ie 01 and year would be
same so 08


I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
Horne, Jim - James S
2008-01-02 15:31:13 UTC
Permalink
NOTICE:
All information in and attached to the e-mail(s) below may be proprietary, confidential, privileged and otherwise protected from improper or erroneous disclosure. If you are not the sender's intended recipient, you are not authorized to intercept, read, print, retain, copy, forward, or disseminate this message. If you have erroneously received this communication, please notify the sender immediately by phone (704-758-1000) or by e-mail and destroy all copies of this message (electronic, paper, or otherwise). Thank you.

Try using the INTNX function. It works something like this:

thismnth = INTNX('MONTH',today(),0) ;
lastmnth = INTNX('MONTH',today(),-1) ;

Hope this helps,

Jim Horne
Lowe's Companies, Inc.

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@gmail.com
Sent: Wednesday, January 02, 2008 10:18 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: DATE FORMATING

I need previous month date and year in a macro variable in mmyy form

Ex: 1
Todays date is 01/02/08
01 is month and 08 is year I need value of previous month

Mm= 12 will be previous month value
YR= 07 the year corresponding to that month

I need 1207 value

Ex2:

If Date in 1st feb 08

I need 0108 value // prev month would be JAN ie 01 and year would be
same so 08


I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
Terjeson, Mark
2008-01-02 15:38:33 UTC
Permalink
Hi,

The INTNX() function performs date
adjusting by a specified increment.

e.g.


data _null_;

todays_date = date();

* adjust with a specified interval ;
prev_month = intnx('month',todays_date,-1,'b');

format prev_month mmyyn5.;

put prev_month=;

run;





Hope this is helpful.


Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investments


Russell Investments
Global Leaders in Multi-Manager Investing






-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@gmail.com
Sent: Wednesday, January 02, 2008 7:18 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: DATE FORMATING

I need previous month date and year in a macro variable in mmyy form

Ex: 1
Todays date is 01/02/08
01 is month and 08 is year I need value of previous month

Mm= 12 will be previous month value
YR= 07 the year corresponding to that month

I need 1207 value

Ex2:

If Date in 1st feb 08

I need 0108 value // prev month would be JAN ie 01 and year would be
same so 08


I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
data _null_,
2008-01-02 15:36:52 UTC
Permalink
17 %put Last Month: %sysfunc(intnx(MONTH,"&sysdate"d,-1),mmyyn5.);
Last Month: 1207
Post by r***@gmail.com
I need previous month date and year in a macro variable in mmyy form
Ex: 1
Todays date is 01/02/08
01 is month and 08 is year I need value of previous month
Mm= 12 will be previous month value
YR= 07 the year corresponding to that month
I need 1207 value
If Date in 1st feb 08
I need 0108 value // prev month would be JAN ie 01 and year would be
same so 08
I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
Peter
2008-01-02 16:05:22 UTC
Permalink
Post by r***@gmail.com
I need previous month date and year in a macro variable in mmyy form
Ex: 1
Todays date is 01/02/08
01 is month and 08 is year  I need value of previous month
Mm= 12 will be previous month value
YR=   07 the year corresponding to that month
I need  1207 value
If Date in 1st feb 08
I need 0108 value  // prev month would be JAN ie 01 and year would be
same so 08
I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
since you want a macro variable, try
%let prevMon= %sysfunc( intnx( month, "&sysdate9"d, -1), mmyyN4 );

only if your SAS session might run over midnight at a month-end would
it create any trouble

***@bigfoot.com has already posted links into Online Doc for
intnx() function, and format mmyyN.

For %sysfunc(), go to the Doc, and drill down into
/ Base SAS/ SAS Macro Language: Reference/Macro Language Dictionary


Happy New Year

PeterC
a***@bigfoot.com
2008-01-02 16:06:52 UTC
Permalink
%let lastmonth=%sysfunc(putn(%sysfunc(intnx(month,
%sysfunc(date()),-1)),mmyyn4.));
%put &lastmonth;

/* Or ... */

data _null_;
lastmonth = put(intnx('month',date(),-1),mmyyn4.);
call symput('lastmonth', lastmonth);
run;
%put &lastmonth;
Post by r***@gmail.com
I need previous month date and year in a macro variable in mmyy form
Ex: 1
Todays date is 01/02/08
01 is month and 08 is year  I need value of previous month
Mm= 12 will be previous month value
YR=   07 the year corresponding to that month
I need  1207 value
If Date in 1st feb 08
I need 0108 value  // prev month would be JAN ie 01 and year would be
same so 08
I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.
r***@gmail.com
2008-01-02 16:17:55 UTC
Permalink
Post by a***@bigfoot.com
%let lastmonth=%sysfunc(putn(%sysfunc(intnx(month,
%sysfunc(date()),-1)),mmyyn4.));
%put &lastmonth;
/* Or ... */
data _null_;
  lastmonth = put(intnx('month',date(),-1),mmyyn4.);
  call symput('lastmonth', lastmonth);
run;
%put &lastmonth;
Post by r***@gmail.com
I need previous month date and year in a macro variable in mmyy form
Ex: 1
Todays date is 01/02/08
01 is month and 08 is year  I need value of previous month
Mm= 12 will be previous month value
YR=   07 the year corresponding to that month
I need  1207 value
If Date in 1st feb 08
I need 0108 value  // prev month would be JAN ie 01 and year would be
same so 08
I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.- Hide quoted text -
- Show quoted text -
It is working fine now, Thank you very much

Regards,
Raghu
r***@gmail.com
2008-01-02 16:21:02 UTC
Permalink
Post by a***@bigfoot.com
%let lastmonth=%sysfunc(putn(%sysfunc(intnx(month,
%sysfunc(date()),-1)),mmyyn4.));
%put &lastmonth;
/* Or ... */
data _null_;
  lastmonth = put(intnx('month',date(),-1),mmyyn4.);
  call symput('lastmonth', lastmonth);
run;
%put &lastmonth;
Post by r***@gmail.com
I need previous month date and year in a macro variable in mmyy form
Ex: 1
Todays date is 01/02/08
01 is month and 08 is year  I need value of previous month
Mm= 12 will be previous month value
YR=   07 the year corresponding to that month
I need  1207 value
If Date in 1st feb 08
I need 0108 value  // prev month would be JAN ie 01 and year would be
same so 08
I was trying using date() to get todays date and using put statement
to get char value and input to get numeric value and also with
substring method but unable to get it.- Hide quoted text -
- Show quoted text -
Wish you all very happy new year

Regards,
Raghu

Continue reading on narkive:
Loading...