DATA Step, Macro, Functions and more

Proc DS2 with Macro date variable

Accepted Solution Solved
Reply
New Contributor nkm
New Contributor
Posts: 2
Accepted Solution

Proc DS2 with Macro date variable

 

%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. 

 

  

 

 


Accepted Solutions
Solution
a month ago
PROC Star
Posts: 2,370

Re: Proc DS2 with Macro date variable

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


All Replies
PROC Star
Posts: 2,370

Re: Proc DS2 with Macro date variable

[ Edited ]

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.

 

 

New Contributor nkm
New Contributor
Posts: 2

Re: Proc DS2 with Macro date variable

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 ?
Solution
a month ago
PROC Star
Posts: 2,370

Re: Proc DS2 with Macro date variable

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.

 

 

Super User
Super User
Posts: 8,126

Re: Proc DS2 with Macro date variable

PROC DS2 does not understand SAS date literals?

Who made that design decision?

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 113 views
  • 2 likes
  • 3 in conversation