BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I've a macro as follows.

 

 

%let reporting_dt=30JUN2018

Then I've to filter the below variable and it should be between 01jun2018 to 30jun2018 of the 'reporting_dt'. I don't want to hard code anything here as the value of the macro variable changes frequently.

 

Trans_date

01jun2018
08jul2017
30apr2018
27jun2018

 

Desired output:

 

Trans_date

01jun2018
27jun2018

 

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

AS with every other post, please show test data in the form of a datastep.  Now, once again we have to have this back and forth as we try to extract the required information from you as to what the data is!!  

What is trans_date?  Is it a character or a numeric?  How are you filtering the data?

If its a date then:

data want;
  set have;
  where trans_date="&reporting_dt."d;
run;

If its character:

data want;
  set have;
  where upcase(trans_dt)="&reporting_dt.";
run;

In future, please post test data in the form of a datastep, show what output you want, show the code you have used, and any log output which occurs.

PaigeMiller
Diamond | Level 26

@Babloo wrote:

I've a macro as follows.

 

 

%let reporting_dt=30JUN2018

 


It will help everyone if we all are using the same (and correct) terminology. You do NOT have a macro. You have a macro variable. 

 

Then I've to filter the below variable and it should be between 01jun2018 to 30jun2018

 

So how does the macro variable relate to the above sentence? There is more information in the above sentence than there is in the macro variable. Where does this extra information come from? We need to understand the logic in order to provide working code.

--
Paige Miller
Astounding
PROC Star

Well, you haven't told us a lot ... is TRANS_DATE numeric?  What should happen if &REPORTING_DT falls in the middle of the month.  Do you need to use SQL, or will a DATA step suffice?

 

So making a guess as to the answers, here is an approach:

 

data want;

set have;

where intnx('month', "&reporting_dt"d, 0) <= trans_date <= "&reporting_dt"d;

run;

Babloo
Rhodochrosite | Level 12
TRANS_DATE is numeric variable. I need all the dates of the reporting month
in TRANS_DATE. Data step or proc sql, anything is OK
ballardw
Super User

@Babloo wrote:
TRANS_DATE is numeric variable. I need all the dates of the reporting month
in TRANS_DATE. Data step or proc sql, anything is OK

It sounds like you are looking for something like:

data want;
   set have;
   where intnx('month',"&reporting_dt."d,0,'B') le trans_date le  intnx('month',"&reporting_dt."d,0,'E');
run;

Which assumes that your trans_date is SAS date valued.

 

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
  • 5 replies
  • 2419 views
  • 0 likes
  • 5 in conversation