File and put Statement

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

File and put Statement

Hi,

Guys, i need to create a external txt file with finame and file statements as follows:

filename out "/home/mm14532/sasuser.v92/FRAUDEEM.txt";

data _null_; set ABECS_V4;
file out ;
put "/home" #2 @2 POS_MODE_OLA @3 DOM_INT @4 PAIS @54 OLA_MIS_MERCH_CAT @58 QUANTIDADE @70 VALOR @85 TIP_PESS @87 FORM_PAG @88 ANO @92 MES;

run;

This code is working well, but i need a way to put at the first line of this external file a string or a title.

I've tried using #2 to go to the second line but it didn't worked.

How can i do that ?

Thank you before anything

Rodrigo Elias


Accepted Solutions
Solution
‎08-14-2015 05:12 PM
Respected Advisor
Posts: 3,156

Re: File and put Statement

Posted in reply to DartibaliRodrigo

Not tested, but can you just add a line:

filename out "/home/mm14532/sasuser.v92/FRAUDEEM.txt";

data _null_; set ABECS_V4;
file out ;

if _n_=1 then put "/home" ;

else put @2 POS_MODE_OLA @3 DOM_INT @4 PAIS @54 OLA_MIS_MERCH_CAT @58 QUANTIDADE @70 VALOR @85TIP_PESS @87 FORM_PAG @88 ANO @92 MES;

run;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: File and put Statement

Posted in reply to DartibaliRodrigo

filename out "/home/mm14532/sasuser.v92/FRAUDEEM.txt";

data _null_;

set ABECS_V4;
file out ;

if _n_ = then put "stuff here will be the first line in the output file";
put "/home" @2 POS_MODE_OLA @3 DOM_INT @4 PAIS @54 OLA_MIS_MERCH_CAT @58 QUANTIDADE @70 VALOR @85 TIP_PESS @87 FORM_PAG @88 ANO @92 MES;

run;

The automatic variable _n_ relates to the record currently being read from the dataset on the set statement.

You could use it for all kinds of conditional processing for old school output like this.

Examples:

if mod(_n_,80) = 0 then put "this is a multiple of 80 lines in the file";

or put the values of some specific variables, possibly you've been accumulating totals...

Solution
‎08-14-2015 05:12 PM
Respected Advisor
Posts: 3,156

Re: File and put Statement

Posted in reply to DartibaliRodrigo

Not tested, but can you just add a line:

filename out "/home/mm14532/sasuser.v92/FRAUDEEM.txt";

data _null_; set ABECS_V4;
file out ;

if _n_=1 then put "/home" ;

else put @2 POS_MODE_OLA @3 DOM_INT @4 PAIS @54 OLA_MIS_MERCH_CAT @58 QUANTIDADE @70 VALOR @85TIP_PESS @87 FORM_PAG @88 ANO @92 MES;

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 190 views
  • 3 likes
  • 3 in conversation