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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info 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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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