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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.