Can you please help me the below requirement.
I need to store date values as below.
data t1;
validfrom=<firstdayoflastmonth> e.g 01APR2023;
ValidTill=<lastdayoflastmonth> e.g 30APR2023;
run;
already, I have another dataset , where above two variables (validfrom and validtill) have dates.
I need to concatenate both of them.
I used something, but this is storing as character, and unable to concatenate.
%let firstdayofthelastmonth = %sysfunc(intnx(month,%sysfunc(today()),-1),date9.);
%let lastdayofthelastmonth = %sysfunc(intnx(month,%sysfunc(today()),-1,e),date9.);
%put &firstdayofthelastmonth.;
%put &lastdayofthelastmonth.;
Kindly suggest.
I'm also not sure what you mean by concatenate, but from the code you shared, I wonder if you're trying to do something like:
%let firstdayofthelastmonth = "%sysfunc(intnx(month,%sysfunc(today()),-1),date9.)"d;
%let lastdayofthelastmonth = "%sysfunc(intnx(month,%sysfunc(today()),-1,e),date9.)"d;
%put &firstdayofthelastmonth.;
%put &lastdayofthelastmonth.;
data t1;
validfrom=&firstdayofthelastmonth;
ValidTill=&lastdayofthelastmonth;
put (_all_)(=) ;
format validfrom validtill date9. ;
run;
What exactly do you need to concatenate? Please provide an example and be specific.
What do you mean by "concatenate"?
Concatenation is a character operation, like
want = x !! y;
There is a major disconnect between this statement:
I have another dataset , where above two variables (validfrom and validtill) have dates.
And your later usage of MACRO CODE.
%let firstdayofthelastmonth = %sysfunc(intnx(month,%sysfunc(today()),-1),date9.);
If you have data in a data step then use SAS CODE to manipulate the data.
So if you want to make new variable that concatenates the values of two dates then you will need to first convert them into STRINGS.
First let's make a dataset with the two date variables.
data HAVE;
validfrom='01APR2023'd;
validtill='30APR2023'd;
format validfrom validtill date9.;
run;
Perhaps by using VVALUE() function so whatever display format you have attached to the variable is used in the conversion?
data want;
set have;
length combined $19 ;
combined=catx('-',vvalue(validfrom),vvalue(validtill));
run;
Result
Obs validfrom validtill combined 1 01APR2023 30APR2023 01APR2023-30APR2023
But I suspect that your real request is something totally different, so please provide more information about what you are actually trying to do.
I'm also not sure what you mean by concatenate, but from the code you shared, I wonder if you're trying to do something like:
%let firstdayofthelastmonth = "%sysfunc(intnx(month,%sysfunc(today()),-1),date9.)"d;
%let lastdayofthelastmonth = "%sysfunc(intnx(month,%sysfunc(today()),-1,e),date9.)"d;
%put &firstdayofthelastmonth.;
%put &lastdayofthelastmonth.;
data t1;
validfrom=&firstdayofthelastmonth;
ValidTill=&lastdayofthelastmonth;
put (_all_)(=) ;
format validfrom validtill date9. ;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.