Macros for YYMMN

Reply
New Contributor
Posts: 4

Macros for YYMMN

Hi,

 

Can someone help me to write the macors for 6 months prior to YYYYMM date in YYMMN format which is already there in Temp dataset as shown below.

 

ID                    Region    YYYYMM

2205500483    3742       201503

1105661211    3411       201410

2010452387    4605       201501

 

data _null_;

call symput('Hist',"'"||put(intnx('month', YYYYMM, -6), YYMMN.)||"'");

run;

%put &Hist.;

 

Proc sql;

Create table Test as

Select id, Region, YYYYMM, &Hist. as Effect_date

from Temp

order by id;

quit;

This step is not working.

Esteemed Advisor
Esteemed Advisor
Posts: 7,192

Re: Macros for YYMMN

You appear to be using Macro (a text generation tool) for what should be a datastep process:

data test;
  set temp;
  effect_date=intnx('month',yymm,-6);
  format effect_date yymm6.;
run;
New Contributor
Posts: 4

Re: Macros for YYMMN

Thanks for the prompt reply!!!

But i get the result in numeric format as 251103, 251012, 251012 even though format is used.

Thanks !!
Esteemed Advisor
Esteemed Advisor
Posts: 7,192

Re: Macros for YYMMN

Dates and times are numeric.  Dates are number of days since Jan1960 for example.  How you display them is by using the apropriate format, e.g. yymm.  If you need a character varaible - i.e. it is no longer a date - then you use put() function:

data test;
  set temp;
  effect_date=put(intnx('month',yymm,-6),yymm6.);
run;
New Contributor
Posts: 4

Re: Macros for YYMMN

The output for effect_date is showing as 11M03, 10M12, 11M03....Not getting in YearMonth (201409)
Esteemed Advisor
Esteemed Advisor
Posts: 7,192

Re: Macros for YYMMN

I would suggest do some reading on formats, a minor change to the format is all that is required, however you should know how to display data using formats, its a key item:

data test;
  yymm="12Aug2011"d;
  effect_date=put(intnx('month',yymm,-6),yymmn6.);
run;
Respected Advisor
Posts: 3,823

Re: Macros for YYMMN

@Nethra

Read very carefully everything under this link:

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n0q9ylcaccjgjrn19hvq...

 

It is very important that you fully understand this and it will make your SAS coding life quite a bit easier if you do so,

New Contributor
Posts: 4

Re: Macros for YYMMN

Thank you all for helping me !!!! The link is useful one.
Ask a Question
Discussion stats
  • 7 replies
  • 95 views
  • 0 likes
  • 3 in conversation