BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DartRodrigo
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

2 REPLIES 2
ballardw
Super User

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...

Haikuo
Onyx | Level 15

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 432 views
  • 3 likes
  • 3 in conversation