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

 

%let sales_date = "01JAN2018"d;

proc ds2;

	data sales_data/overwrite = 'YES';
		retain count;

		method run();
			set {select * from sales.sales_data where sales_date >=&sales_date. };

		end;

	enddata;
run;
quit;

Hi , I want to understand how to use macro date variable in PROC DS2. sales_date is macro variable and want to use fetch data from sas dataset sales.sales_data after this date. There has been lot of other codes also so jsut added only relevant code to show what is needed. Overall, how to use macro variable in proc ds2 which is sas date. 

 

  

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

%let sales_date = '01jan2018'd;

data TEST; 
  D='01jan2018'd;
run;

proc ds2;
  data T/overwrite = 'YES';
    method run();
      set { select * from TEST where D = date%nrbquote('%sysfunc(putn(&sales_date.,yymmddd10.))') };
    end;
  enddata;
run;
quit;

NOTE: Execution succeeded. One row affected.

 

 

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Macro variables work fine.

Your syntax is incorrect.

This works:

%let sales_date = date'2018-01-01';

data TEST; 
  D='01jan2018'd;
run;

proc ds2;
  data T/overwrite = 'YES';
    method run();
      set { select * from TEST where D = &sales_date. };
    end;
  enddata;
run;
quit;

NOTE: Execution succeeded. One row affected.

 

 

nkm
Calcite | Level 5 nkm
Calcite | Level 5
Thanks ChrisNZ for your help. Sorry if I was not clear but what I was looking for how to use "01JAN2018"d. Is there any way to use the same by converting it to ds2 date type or it is not possible to use D type of string in proc ds2. to_double("01JAN2018"d) --- is there any way to use ?
ChrisNZ
Tourmaline | Level 20

Like this?

%let sales_date = '01jan2018'd;

data TEST; 
  D='01jan2018'd;
run;

proc ds2;
  data T/overwrite = 'YES';
    method run();
      set { select * from TEST where D = date%nrbquote('%sysfunc(putn(&sales_date.,yymmddd10.))') };
    end;
  enddata;
run;
quit;

NOTE: Execution succeeded. One row affected.

 

 

Tom
Super User Tom
Super User

PROC DS2 does not understand SAS date literals?

Who made that design decision?

What other types of SAS literals does PROC DS2 not understand?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1823 views
  • 3 likes
  • 3 in conversation