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.
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;
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;
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;
Read very carefully everything under this link:
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,
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.