Hello, I have a dataset that lists dates, and the corresponding YYMMM (for example September 2021 is 21M09).
I would like to take the interval of 21M02 to 23M09 and assign the values 1 through 32 to these in order.
Using a macro is preferable in case I need to change this interval. Any suggestions? Thanks!!
@l3xrink wrote:
Hi there are multiple rows that i would like to assign the value of 1,2, etc. depending on the value of YYMMM.
If you want to assign 1,2,3 just use a retained variable.
data want;
set have;
by id;
seq+1;
if first.id then seq=1;
run;
If you want to convert MONTH into relative month number then use INTCK() function. Add one if you want to number from 1 instead of from 0.
If they are not already dates that just have the YYMM5. format attached (who displays dates without the century number?).
%let basedate = '01jan2011'd;
data want;
set have;
month_number = 1 + intck('month',&basedate,yymmm);
run;
If they are strings then first convert them into a date value.
%let basedate = '01jan2011'd;
data want;
set have;
month_number = 1 + intck('month',&basedate,input(cats(compress(yymmm,'Mm'),'01'),yymmdd.));
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.