BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shubham1
Calcite | Level 5
FILENAME new "C:\new\abc.txt";

 

data _null_;

  file new dsd dlm = ';';

  set atmdata;

  format txt $18.;

  by client_no atm_id;

  if _N_ = 1 then

    put 'name;'

        'ATM ;'

        'transacation_number;'

       

    ;

 

put client_no

     atm_id

     Transacation

    

     ;

 

 

run;

filename NEW;

I am writing above code to write data set atmdata to a file new

Now I want same data set to be written into different directory


FILENAME new1 "D:\new1\abc.txt";


I do not want to write data statement again to write into different directory

Can i write two filename staemnet with one data step ?

How can i acheive that

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

I think you need another data step. Add this after the step you have:

FILENAME new1 "C:\temp\abc1.txt";
data _null_;    
  rc = fcopy('new','new1');
run;

 

 

View solution in original post

5 REPLIES 5
Reeza
Super User

You could probably do it with a loop but FCOPY is probably more efficient, which would copy the written file, which is faster than writing to two places. 

 

data _null_;

set have end=eof;




...rest of code;



if eof then do;
rc = fcopy(....);
end;

run;

@shubham1 wrote:
FILENAME new "C:\new\abc.txt";

 

data _null_;

  file new dsd dlm = ';';

  set atmdata;

  format txt $18.;

  by client_no atm_id;

  if _N_ = 1 then

    put 'name;'

        'ATM ;'

        'transacation_number;'

       

    ;

 

put client_no

     atm_id

     Transacation

    

     ;

 

 

run;

filename NEW;

I am writing above code to write data set atmdata to a file new

Now I want same data set to be written into different directory


FILENAME new1 "D:\new1\abc.txt";


I do not want to write data statement again to write into different directory

Can i write two filename staemnet with one data step ?

How can i acheive that


 

shubham1
Calcite | Level 5

Can you give me a code as I am not able to get it how it should write 

ChrisNZ
Tourmaline | Level 20

I think you need another data step. Add this after the step you have:

FILENAME new1 "C:\temp\abc1.txt";
data _null_;    
  rc = fcopy('new','new1');
run;

 

 

SASKiwi
PROC Star

Something like this should work:

 

data _null_;

  set atmdata;

  format txt $18.;

  by client_no atm_id;

  file new dsd dlm = ';';
  link WriteFile;

  file new2 dsd dlm = ';';
  link WriteFile;

WriteFile:
  if _N_ = 1 then

    put 'name;'

        'ATM ;'

        'transacation_number;'

    ;

put client_no

     atm_id

     Transacation
     ;

return;
run;
shubham1
Calcite | Level 5

Thanks It worked now 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1480 views
  • 5 likes
  • 4 in conversation