BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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;

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

What exactly do you need to concatenate? Please provide an example and be specific.

Tom
Super User Tom
Super User

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.

 

 

 

Quentin
Super User

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;

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.

sas-innovate-white.png

🚨 Early Bird Rate Extended!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1039 views
  • 1 like
  • 5 in conversation