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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Jagadeesh2907
Obsidian | Level 7

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 ? 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1333 views
  • 0 likes
  • 2 in conversation