BookmarkSubscribeRSS Feed
SannaSanna
Quartz | Level 8

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;

7 REPLIES 7
ballardw
Super User

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.

SannaSanna
Quartz | Level 8

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

*/

data_null__
Jade | Level 19

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

SannaSanna
Quartz | Level 8

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?

ballardw
Super User

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.

SannaSanna
Quartz | Level 8

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  */

ballardw
Super User

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)

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!

What is Bayesian Analysis?

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.

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
  • 7 replies
  • 1018 views
  • 1 like
  • 3 in conversation