BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

Hi I have 3 SAS datasets, each having 75 variables.  I need to create them in text file with fixed lengths.  What is the best way to do that?

Thanks. 

7 REPLIES 7
Reeza
Super User

A customized data step. 

 

You can use use the info from sashelp.vcolumns (length/type/format) to help generate the info required for the code...or even the code. 

podarum
Quartz | Level 8

Thank you Reeza,  but how do I now integrate this into a code?

Reeza
Super User

See the example here. 

 

http://www.ats.ucla.edu/stat/sas/faq/write_fixedformat.htm

 

Determining the locations (@#) is based on length which can be obtained from dictionary tables or proc contents. 

Ksharp
Super User

What do you mean by fixed length. Can you post an example ?

 

filename x 'c:\temp\x.csv' ;
data _null_;
set sashelp.class;
 file x ;
 length temp $ 40;
 temp=catx(',',of _all_);
 len=40;
 put temp $varying40. len;
run;

x.png

podarum
Quartz | Level 8

I have no idea.. it's a request from someone that it must be fixed length.  So here's what I did:

 

filename out_pipe "P:\Data\new_bo1.txt";

data _null_; set pdrive.new_bor1;

file out_pipe;

put "|" ACEAmount

"|" ACEDate.....

run;

Peter_C
Rhodochrosite | Level 12

PUT statement default behaviour for a list of variables would place single blanks (default delimiter) between vars.
Consider the brevity of:
FILE "YOUR FILE.CSV" DSD LRECL=1000 ;
PUT (_ALL_)( : ) ;
One way to achieve fixed layout would be to specify the formats with widths for each variable in the PUT.
It makes a fine example for use of the dictionary.columns metadata.
Just one question ... what default format/width would you wish for numeric values with no defined format?
The default BEST12. provides floating point notation for large numeric values.....
Once the required choices of width are clarified, a bit of SQL and a simple data step could be written by a student.
In a fixed layout, delimiters would not be needed, but might reduce any importer's need for proper definition of the column layout.
I believe the fixed positions layout would probably be faster to import than traditional csv ... (less cpu time, but more expensive in disk space and i/o) but any benefit will only become apparent for very large data.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 7924 views
  • 1 like
  • 5 in conversation