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;

 

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: 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;

 

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 570 views
  • 1 like
  • 5 in conversation