When discussing features or asking for programming help, sharing a minimum working example (MWE) is often required. In my experience with SAS software, the data source causing questions is often not directly entered into a SAS data step but brought in from an outside source such as an Excel or CSV file or similar. When creating an MWE it is then necessary to manually create a data step. This program is intended to make that process quicker and easier. The goal of the program is to iterate over a given CSV file and convert it to a simple SAS data step template.
Pass the name of a file or a -
to process input from the command line:
csv2ds file1.csv // creates a data file1 statement from file1.csv contents
csv2ds - // creates a data SAMPLEDATA statement from STDIN contents
Reading from the command line allows for input to be piped to CSV2DS. The idea behind that is compatibility with CSVKIT.
A list of data steps can be generated by passing multiple files to CSV2DS. STDIN and files can be combined:
cat file1.csv | csv2ds - file2.csv file3.csv
This package can be installed with the standard Go toolchain.
go install github.com/dmsenter89/csv2ds@latest
This program is still quite basic. It uses fairly simplistic parsing to guess whether a particular column is numeric or not, in which case it defaults to a string representation. A length statement is added to correctly read in string arguments without truncation. If special formats or dates are used, manual intervention will be needed to have SAS process the inputs as desired.