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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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