07-20-2012 09:31 PM
I have a requirement based on store branches I have to create .csv files on to a drive.
I used Filename FTP to create .csv files on the drive,but the problem is certain branches does have empty files,in that case i do not want to create output files on the drive for that branch.
How can I achieve this?Please share your thoughts.
07-23-2012 11:41 AM
Below is the code I am using:
IF MCA = "&MCA1" THEN DO;
FILE &FNME1 DSD DLM=',';
PUT MCA MRN1 ADMDT DISDT
%IF &TEXT_FLG = Y %THEN %DO;
FILENAME NCHS01 "&HLQO" DISP=SHR;
FILENAME NCHS FTP
CD = "&CD"
LRECL = &OUT_LRECL
INFILE NCHS01 SHAREBUFFERS;
In the MCA value FOLM is not in my input file,but the ftp statement is creating an empty file in my ftp location.I dont want FTP an empty file.Please help.
07-23-2012 02:00 PM
I don't know if this will solve everything, but it might.
The most obvious flaw in your program is trying to use a DATA step IF/THEN to control whether or not %LET executes. %LET always executes. If you examine your log, you will see that %PUT &TEXT_FLG; always writes Y. To change that, change the second %LET statement to read:
CALL SYMPUT('TEXT_FLG', 'Y');
Move the final RUN statement earlier, just before testing for %IF &TEXT_FLG=Y. That forces the DATA step to run before you check the value of &TEXT_FLG. FILENAME statements are not part of a DATA step, anyway.
Also, move the %PUT statement to the very end of the macro. If you leave it in its current location, it will write the value of &TEXT_FLG BEFORE the DATA step executes.
07-23-2012 02:03 PM
First reverse the order of your INPUT and your FILE statements in the DATA step and see if it helps. Perhaps if SAS stops on an empty input file before getting to the FILE statement it might not send anything to FTP.
Can you get the FTP to work using FTP engine in the FILE statement in the DATA _NULL_ instead using the FILENAME statement.
That might make it more likely to skip writing the file.
Do you really want the SHAREBUFFERS options on your INFILE statement as you are writing to a different output file? Not sure this makes any difference for this problem.
07-23-2012 10:29 PM
It looks like you are querying some obs rely on a condition . Here is an example . You need to vary it to suit your taste.
%MACRO MCASPLT(sex,FNME1,F1); proc sql; create table temp as select * from sashelp.class where sex="&sex" ; quit; %if &sqlobs ne 0 %then %do; proc print ;run;%end; %MEND; %mcasplt(F,FNME1,F1)