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,
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.