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 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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