BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
miss2223
Fluorite | Level 6

Below is my code. No error running the code, but I want to see the output data. Is there a way to check the output for 'customer_details' from SAS? Also I want to export the data to excel after. 

 

%macro TECHNOLOGY();
%let _DT1=2022-03-01;
%let DT1=%sysfunc(inputn(&_DT1, yymmdd10.), date9.);
%put &DT1.;

%let _DT2=2022-08-31;
%let DT2=%sysfunc(inputn(&_DT2, yymmdd10.), date9.);
%put &DT2.;

data customer_details;
set work.installation;
where Contract = 'Y' AND Colour in ('Red', 'Orange', 'Blue')
and contract_date_start="&dt1"d and contract_date_end="&dt2"d;
run;
%mend TECHNOLOGY;

 

Many Thanks!! 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@miss2223 wrote:

Below is my code. No error running the code, but I want to see the output data. Is there a way to check the output for 'customer_details' from SAS? Also I want to export the data to excel after. 

 

%macro TECHNOLOGY();
%let _DT1=2022-03-01;
%let DT1=%sysfunc(inputn(&_DT1, yymmdd10.), date9.);
%put &DT1.;

%let _DT2=2022-08-31;
%let DT2=%sysfunc(inputn(&_DT2, yymmdd10.), date9.);
%put &DT2.;

data customer_details;
set work.installation;
where Contract = 'Y' AND Colour in ('Red', 'Orange', 'Blue')
and contract_date_start="&dt1"d and contract_date_end="&dt2"d;
run;
%mend TECHNOLOGY;

 

Many Thanks!! 


Perhaps you need to actually call the macro at the end?

 

%macro TECHNOLOGY();
%let _DT1=2022-03-01;
%let DT1=%sysfunc(inputn(&_DT1, yymmdd10.), date9.);
%put &DT1.;

%let _DT2=2022-08-31;
%let DT2=%sysfunc(inputn(&_DT2, yymmdd10.), date9.);
%put &DT2.;

data customer_details;
set work.installation;
where Contract = 'Y' AND Colour in ('Red', 'Orange', 'Blue')
and contract_date_start="&dt1"d and contract_date_end="&dt2"d;
run;
%mend TECHNOLOGY;
%technology()   /* <-- you have to actually call the macro, like this */
--
Paige Miller

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

I don't understand the question. 

Just look at the data the same way you would any other SAS dataset.

 

For example you could just use PROC PRINT.

proc print data=customer_details;
run;

There is no need to define a macro to run that code.  There is nothing conditional happening there.  The %LET statements will work fine as open SAS code instead.

 

Also there is also no need to set the macro variables to one representation of a date and then convert them to another.  Why not just start with the date in a style that will work with the date literals to begin with?

andreas_lds
Jade | Level 19

Sorry, but i don't understand the problem, too.

 

I would remove all macro statements and verify that the program does, what it should do. Your macro-variables should not start with an underscore, some automatic variables, like _ClientProjectPath, use the underscore to identify them as automatic variables.

So the data step would look like

data customer_details;
  set work.installation;
  where Contract = 'Y' AND Colour in ('Red', 'Orange', 'Blue')
    and contract_date_start="01Mar2022"d and contract_date_end="31Aug2022"d;
run;

Now the export:

proc export data= work.customer_details dbms= xlsx file= "PATH/customer_details.xlsx" replace;
run;

Why do you want a macro at all?

 

Note: code is untested.

miss2223
Fluorite | Level 6

Thanks for explaining it. 

 

It works fine without having %macro TECHNOLOGY; on the top row. 

 

May I ask why having %macro SAS does not give the output data tab as usual? I realised quite a few of the macro code are doing the same thing. 

 

PaigeMiller
Diamond | Level 26

@miss2223 wrote:

Below is my code. No error running the code, but I want to see the output data. Is there a way to check the output for 'customer_details' from SAS? Also I want to export the data to excel after. 

 

%macro TECHNOLOGY();
%let _DT1=2022-03-01;
%let DT1=%sysfunc(inputn(&_DT1, yymmdd10.), date9.);
%put &DT1.;

%let _DT2=2022-08-31;
%let DT2=%sysfunc(inputn(&_DT2, yymmdd10.), date9.);
%put &DT2.;

data customer_details;
set work.installation;
where Contract = 'Y' AND Colour in ('Red', 'Orange', 'Blue')
and contract_date_start="&dt1"d and contract_date_end="&dt2"d;
run;
%mend TECHNOLOGY;

 

Many Thanks!! 


Perhaps you need to actually call the macro at the end?

 

%macro TECHNOLOGY();
%let _DT1=2022-03-01;
%let DT1=%sysfunc(inputn(&_DT1, yymmdd10.), date9.);
%put &DT1.;

%let _DT2=2022-08-31;
%let DT2=%sysfunc(inputn(&_DT2, yymmdd10.), date9.);
%put &DT2.;

data customer_details;
set work.installation;
where Contract = 'Y' AND Colour in ('Red', 'Orange', 'Blue')
and contract_date_start="&dt1"d and contract_date_end="&dt2"d;
run;
%mend TECHNOLOGY;
%technology()   /* <-- you have to actually call the macro, like this */
--
Paige Miller