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

Hi everybody,

 

my need is to execute a proc export all the days in the programme, but i want to obtain the output file only if the day of the week is tuesday. Could you please help me?

 

I wrote a datastep like this but it doesn't work. Why?

 

data _null_;

if WEEKDAY(today())=3 then do;

PROC EXPORT DATA= RLWORK.prova

OUTFILE= "DIRECTORY"

DBMS=DLM REPLACE LABEL;

DELIMITER='3B'x;

 

PUTNAMES=YES;

RUN;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
saspert
Pyrite | Level 9

afaik, you cannot have a proc export within a datastep. try macro programming instead. 

%macro _xprt;

%if sysfunc(WEEKDAY(today())) = 3 %then %do;

PROC EXPORT DATA= RLWORK.prova

OUTFILE= "DIRECTORY"

DBMS=DLM REPLACE LABEL;

DELIMITER='3B'x;

 PUTNAMES=YES;

RUN;

%end;

%mend _xprt;

%_xprt;

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20
You need some macro logic here.
If you aren't on latest maintenance level you need to wrap you code inside a macro, and in there do %If on the weekday.
The alternative is to do he test in a data step, and if positive issue a call execute that contains your PROC EXPORT.
Data never sleeps
saspert
Pyrite | Level 9

afaik, you cannot have a proc export within a datastep. try macro programming instead. 

%macro _xprt;

%if sysfunc(WEEKDAY(today())) = 3 %then %do;

PROC EXPORT DATA= RLWORK.prova

OUTFILE= "DIRECTORY"

DBMS=DLM REPLACE LABEL;

DELIMITER='3B'x;

 PUTNAMES=YES;

RUN;

%end;

%mend _xprt;

%_xprt;

ballardw
Super User

Here's an example of @LinusH call execute suggestion:

 

data _null_;
   if WEEKDAY(today())=3 then do;
      Call execute ('PROC EXPORT DATA= RLWORK.prova
      OUTFILE= "DIRECTORY"
      DBMS=DLM REPLACE LABEL;
      DELIMITER="3B"x; 
      PUTNAMES=YES;
      RUN;');
   end;
run;

Assumes of course that your outfile is substituted with something that will work. Not sure why you are using the hex "3B"x instead of

 

";" though.

LinusH
Tourmaline | Level 20
Well you can't execute a PROC within a data step, but you can issue/call it. Either with CALL EXECUTE that holds the PROC code (as shown by @ballardw), or to a macro that holds the program.
Either way, the PROC will be queued and execute right after data step termination.
Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 689 views
  • 1 like
  • 4 in conversation