BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DanD999
Quartz | Level 8

I'm trying to export some data to a fixed width text file. I can export the data okay. The problem is that the customer wants the last column (Filler) to be 42 characters. When I look at the file in a hex editor I only see 2 spaces at column 121. How can I add those extra spaces? Also how do I add column names if I want to?

 

Thanks

data _null_;
  set final end=last;
  file "&&loc_&server_dest./&TextOut." LRECL=162 TERMSTR=crlf  recfm=v;
  put
    @1  submitter_id
    @11 ssn
    @22 incentive_met_date
    @30 incentive_code
    @40 incentive_amount
    @50 ssn_of_the_qualifier
    @61 birth_date_of_qualifier
    @69 first_name_of_qualifier
    @94 last_name_of_qualifier
    @119 relationship_code_of_qualifier
	@121 Filler
  ;
run;

data have;
input @1 submitter_id $6.
   	@8 ssn $9.
    @18 incentive_met_date $8.
    @27 incentive_code $4.
/*    @40 incentive_amount $10.*/
/*    @50 ssn_of_the_qualifier $11.*/
/*    @61 birth_date_of_qualifier $8.*/
/*    @69 first_name_of_qualifier $25.*/
/*    @94 last_name_of_qualifier $25.*/
    @32 relationship_code_of_qualifier $2.
;
datalines;
UHCCOE 199997187 20210119 BACK M
UHCCOE 252599991 20210118 BACK M
UHCCOE 289990538 20210125 BACK S
;
RUN;

I' 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

You have recfm=v which apparently eliminates trailing blanks in filler.  But changing to recfm=f will apparently drop the CRLF at the end of each line (just did a test on my windows machine).

 

Change the end of your PUT statement from

	@121 Filler

to

	@121 Filler $42.

Doing that caused my sas log to report maximum length and minimum length of output records both at 162, even with a total blank FILLER.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

You have recfm=v which apparently eliminates trailing blanks in filler.  But changing to recfm=f will apparently drop the CRLF at the end of each line (just did a test on my windows machine).

 

Change the end of your PUT statement from

	@121 Filler

to

	@121 Filler $42.

Doing that caused my sas log to report maximum length and minimum length of output records both at 162, even with a total blank FILLER.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
DanD999
Quartz | Level 8

@mkeintz wrote:

You have recfm=v which apparently eliminates trailing blanks in filler.  But changing to recfm=f will apparently drop the CRLF at the end of each line (just did a test on my windows machine).

 

Change the end of your PUT statement from

	@121 Filler

to

	@121 Filler $42.

Doing that caused my sas log to report maximum length and minimum length of output records both at 162, even with a total blank FILLER.


It worked. Do you know how to add column headings? Thanks so much.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2491 views
  • 0 likes
  • 2 in conversation