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;
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.
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
*/
When you ran the program and examined the TXT file what characters did you find in columns 24-43?
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?
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.
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 */
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)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.