Hi
I have a macro variable which has the date in a below format.
%let yyyymmdd_d1 = 20181201;
I want to use this in a condition where my dataset has a source_date value as number 8 and format yymmdd10. please help for this scenario.
Example code:
In the below code, this will work if i hardcode the dates. But if i want to use this macro variable, it will not accept since the source_date value in the customer dataset is in num8 and with format yymmdd10.
proc sql;
create table work.inventory as
select cust_nbr, annual_income
from customer_&yyyymmdd_d1
where source_date eq "01Dec2018"d;
QUIT;
Something like:
proc sql; create table work.inventory as select cust_nbr, annual_income from customer_&yyyymmdd_d1 where source_date eq input("&yyyymmdd_d1.",yymmdd8.); quit;
Something like:
proc sql; create table work.inventory as select cust_nbr, annual_income from customer_&yyyymmdd_d1 where source_date eq input("&yyyymmdd_d1.",yymmdd8.); quit;
Hi,
Thank you for the solution. Can you tell me what is the variable type of a macro ? will it be treated as character or will be based on the value of the macro variable ?
Macro varibles are always text. They cannot be anything else. Macro is a find/replace text generator which happens before code compilation. This is why we always recommend to use Base SAS - this is the programming language with all the data types, functions etc. and that which gets compiled, rather than using macro which is nothing more than a find/replace system. Macro has its place, but that place is not to replace Base SAS coding.
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!
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.