BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Stretlow
Obsidian | Level 7

 

Hi there.

 

I have a data set where the dates are stored as character so i use a substring to retrieve the data

 

Where = (substr(CaseCreatedDateTime,1,7) in ("2018-09","2018-08")));

 

The dates need to change each month to the current month and previous month so i'm trying to teach myself to do it in a macro.

 


data test;

format Temp_TM Temp_LM DDMMYY10.;
Temp_TM=Today();
Temp_LM=intnx('month',Temp_TM,-1,'b');

month=put(month(Temp_TM),z2.);

ThisMonth1=cat((Year(Temp_TM)),"-",(put(Month(Temp_TM),z2.)));
LastMonth1=cat((Year(Temp_LM)),"-",(put(Month(Temp_LM),z2.)));


run;

which gives me two variables with the year and month in in the format above however when i try to reference them sas is seeing it as numeric so it wont work.

 

Where = (substr(CaseCreatedDateTime,1,7) in (&This_Month,&Last_Month);

i think i need to add quotes around the dates in the macro but am struggling to do it.

 

Any help greatly appreciated.

 

Stret

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
data_null__
Jade | Level 19
("&This_Month","&Last_Month");
Stretlow
Obsidian | Level 7

jesus i've overthought that just a little haven't i.

 

Thank you for your help 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 2944 views
  • 1 like
  • 2 in conversation