BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

Hi,

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.

6 REPLIES 6
Patrick
Opal | Level 21

You could test if there is data before you execute the filename FTP. May be you should post your code so we can suggest some changes to it.

Ksharp
Super User

Yes. I can firstly check whether there are some obs in a dataset by using DICTIONARY.TABLES.

Ksharp

renjithr
Quartz | Level 8

Below is the code I am using:

%MACRO MCASPLT(MCA1,FNME1,F1);

DATA _NULL_;

  SET DATAOT1.NBARI;

  %LET TEXT_FLG=N;

  IF MCA = "&MCA1" THEN DO;

   %LET TEXT_FLG=Y;

   %PUT &TEXT_FLG;

   FILE &FNME1  DSD DLM=',';

   PUT MCA MRN1 ADMDT DISDT

       ;

  END;

%IF &TEXT_FLG  =  Y  %THEN %DO;

    %LET OUT_LRECL=8000;

    %LET CD=ISM\LG\NCAL\TEST;

    %LET HLQO=HPS2.Y3012.XAAA.&F1..TXTOUT;

    %LET OUT_NAME=XAAA.&F1;

    FILENAME NCHS01 "&HLQO" DISP=SHR;

       FILENAME NCHS FTP

                "&OUT_NAME"

                &HOST_PORT_USER_PASS

                CD = "&CD"

                LRECL = &OUT_LRECL

                ;

       RUN;

       DATA _NULL_;

         INFILE NCHS01 SHAREBUFFERS;

         FILE NCHS;

         INPUT;

         PUT _INFILE_;

        RUN;

   % END;

RUN;

%MEND;

%MCASPLT(ANTCH,DATAO02,ANTI);

%MCASPLT(FOLM,DATAO03,FOLS);

ENDSAS;

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.

Astounding
PROC Star

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.

Good luck.

Tom
Super User Tom
Super User

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.

Ksharp
Super User

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)

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 869 views
  • 0 likes
  • 5 in conversation