Help using Base SAS procedures

write output file

Reply
Contributor
Posts: 57

write output file

Hello-

I am trying to write an output file based on pointer positions.  A shortened version of the file is below.  I want to make sure that my code below will export all data correctly (even blanks) and at the end of each row a crlf is included.  I didnt include a lrecl .should it be required?    Would appreciate any feedback.  Thank you

DATA _NULL_;

SET I.ALL_WITCDS_FINAL_ADD;

file 'I:\COData\DataReq/rawinfo.TXT';

put @1 LEA @18 ESIID;

run;

Super User
Posts: 10,550

Re: write output file

If the last variable is longer than 238 characters you may need to add a LRECL parameter to the FILE statement to make the line long enough to prevent truncation. The PUT statement will put whichever line ender is appropriate for the operating system SAS is running under. Assuming a Windows OS then CR-LF will be there.

Blanks for ESIID may only take up one character. If you need them longer some options may be needed depending on what you want.

I don't see an attachment if one was intended but the code looks like it shoulr work.

Contributor
Posts: 57

Re: write output file

Okay- so how to insert blank spaces?  Here is more info on the dataset I am to build:  How do I insert purposeful blank spaces in position 24-43?

DATA _NULL_;
SET I.ALL_WITCDS_FINAL_ADD;
file 'I:\COData\rawinfo.TXT';
put @1 LEA @18 ESIID @44 TOTAL_CNT;
run;


/* LENGTH OF LEA 1-17
  Length of esiid 18-23
  BLANK 24-43
Length of Total_cnt 44-54

*/

Respected Advisor
Posts: 3,777

Re: write output file

When you ran the program and examined the TXT file what characters did you find in columns 24-43?

Contributor
Posts: 57

Re: write output file

did not look right for the position beginning with the blank.  At position 24 there is a '.' (period) and blank spaces after and data picks up at position 44 correctly.  (cannot get the entire field 24-43 to be blank- must be at those specific positions)   Also the length of esiid could vary if that makes a difference?

Super User
Posts: 10,550

Re: write output file

The period is likely to appear when a variable is numeric and the value is missing. Use OPTIONS MISSING=' '; before the data step to get a blank for missing values, or assign a format that will do that.

Contributor
Posts: 57

Re: write output file

Okay-

So will the data within ESIID occupy positions 18-23 even if I dont reference the blank positions 24-43?   ESIID does not always fill up the entier 18-23.  How can I ensure blanks are fully in position 24-43 if I dont reference it in my infile statement?

DATA _NULL_;
SET I.ALL_WITCDS_FINAL_ADD;
file 'I:\COData\rawinfo.TXT';
put @1 LEA @18 ESIID @44 TOTAL_CNT;      <<==  I never reference blank for position 24-43 here. 
run;


/* LENGTH OF LEA 1-17
  Length of esiid 18-23
  BLANK 24-43
Length of Total_cnt 44-54  */

Super User
Posts: 10,550

Re: write output file

With the variable Total_Cnt at position 44 everything from column 18 to 43 should have blanks if ESIID is missing and options missing=' ' is set.

If you are worried about and end or record occurence with no following variables but need blanks then you want a combination of LRECL on the file statement to set the desired length in characters and PAD to fill the line to the length set by LRECL with blanks. Something like

File "myfilename" LRECL=80 Pad;

to create a fixed 80 column output (of course you'll get unexpected results if you put more than 80 characters to the line)

Ask a Question
Discussion stats
  • 7 replies
  • 241 views
  • 1 like
  • 3 in conversation