BookmarkSubscribeRSS Feed
Roddy
Calcite | Level 5

I created this macro:

%LET date = %SYSFUNC(today());
%LET startmonth = %STR(%")%SYSFUNC(intnx(month,&date,-6),yymmn6.)%STR(%");
%LET endmonth = %STR(%")%SYSFUNC(intnx(month,&date,-4),yymmn6.)%STR(%");
%PUT &startmonth &endmonth;

 

I want to the variable YearMonth to fall in between my startmonth and endmonth macros. Using the below statement gives me the error: Expression using IN has components that are of different data types.  YearMonth is (float,null).

PROC SQL;
CREATE TABLE Policy AS
SELECT
A.Policy,
A.PlanCode,
A.I_EmpID,
A.YearMonth
FROM
TestData A
WHERE
A.System = 'NPS'
AND DistributionChannel = 'Direct'
AND "&startmonth" <= YearMonth <= "&endmonth"
;
QUIT;

 

1 REPLY 1
Reeza
Super User
Macro variable is text replacement, so your macro variables are replaced where you indicate which resolves to:

11568 %PUT &startmonth &endmonth;
"201506" "201508"


Which translates to
"&startmonth" <= YearMonth <= "&endmonth"
""201506"" <= YearMonth <= ""201508""

Issues with this:
1. too many quotation marks
2. Types don't match char vs num.

Fix:
1. Remove quotes from macro variable
2. Remove quotes from And condition

%LET date = %SYSFUNC(today());
%LET startmonth = %SYSFUNC(intnx(month,&date,-6),yymmn6.);
%LET endmonth = %SYSFUNC(intnx(month,&date,-4),yymmn6.);
%PUT &startmonth &endmonth;

AND &startmonth <= YearMonth <= &endmonth

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 672 views
  • 0 likes
  • 2 in conversation