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-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
  • 3 replies
  • 1015 views
  • 0 likes
  • 2 in conversation