COPY Instruction |
COPY(options) start end list of series
< text cards >lines to be reproduced as comments (only with HEADER option)
COPY is used to write data series out to a file in any of a variety of formats, and is generally preceded by an OPEN COPY command supplying the name of the file you want to create. COPY can also be used to display data in the output window, but the PRINT command is usually more convenient for this.
Wizards
From a Series List window, you can Export (the export operation is on the File menu, toolbar and the contextual menu) a selected set of series. This doesn't have the flexibility of COPY regarding the range of data exported (it will export the entire series), but since that's what you typically would want, it can often be used rather than the instruction when you are doing a one-off creation of a data file.
Parameters
start, end |
Range of entries to be printed or copied to a file. By default, COPY uses the smallest range required to show all defined data for the series. Any undefined data are treated as missing values. |
list of series |
List of series to be printed or saved. If you omit the list, all current series are printed. |
Options
FORMAT=[FREE]/BINARY/CSV/DBF/DIF/FREE/HTML/PORTABLE/PRN/RATS/RTF/TEX/TSD/WKS/XLS/XLSX/"(FORTRAN format)"
Format to be used.
ORGANIZATION=COLUMNS/[ROWS]
The option ORGANIZATION (or ORG) tells RATS how the data should be organized on the file. Use COLUMNS if you want the data arranged in columns (that is, series run down the page in columns, with each row containing a single observation for all series). Use ROWS if you want the series to run across the page in rows.
Note that COPY still supports the choices OBSERVATION (equivalent to COLUMNS) and VARIABLE (equivalent to ROWS) used in older versions. The ORG option is ignored for most formats, since only text files and spreadsheets allow for the different arrangements.
UNIT=[COPY]/OUTPUT/other unit
This option sets the destination of the COPY operation. This can be an external file or the current OUTPUT unit. The default choice is the COPY unit, which you open with the instruction OPEN COPY. If you don’t open the unit in advance, RATS will prompt you for a file name.
DATES/[NODATES]
With the DATES option, observations are labeled with dates or entry numbers (if no CALENDAR is in effect). With NODATES, observations are not labeled at all.
PICTURE="picture style formatting string"
This allows you to provide a picture picture code to control the formatting of the output. This applies to "text" formats FREE, PRN, RTF, DIF, CSV, TSD, TEX and HTML. Formats which produce a spreadsheet or database, such as XLSX or WKS, will always write the full double precision value.
SMPL=Standard SMPL option [unused]
HEADER=number of header lines [0]
Number of text cards (per series) supplying headers. Follow the COPY instruction with the indicated number of lines of text. These lines are printed above the data or added to the top of the data file. Note: HEADER does not work with the BINARY or spreadsheet formats.
Notes
For most file formats, the COPY command creates a new file, replacing any existing file with the same name. For this reason, you cannot use multiple COPY commands to append data to a single file. If you have a repetitive process that is generating data that needs to be saved in a single file, you first need to collect all the data in a set of series, and then write the series to disk using a single COPY command. VECTORS of SERIES can often be very useful in these situations.
The only exceptions to this are when you are writing text files using the FREE or FORTRAN formats. For these formats, you can use multiple COPY commands to append data to a single file, as long as you don’t close the file between COPY commands. After doing OPEN COPY, the first COPY will create the new file (replacing any previously existing file with that name). Subsequent COPY commands will continue to write to the file until you quit RATS, issue a CLOSE COPY command, or use OPEN COPY to supply a different file name. If you do want to append data to a file that has been closed, use the APPEND option on the OPEN COPY command to reopen the file.
Using FORMAT=FREE
COPY with FORMAT=FREE is not quite analogous to DATA with FORMAT=FREE: if you use the DATES option, COPY will produce a file which DATA cannot process. Use FORMAT=FREE in one of two situations:
•You are porting data to a program which cannot accept any of the “labeled” formats. You will get a file which consists of numbers only.
•You want to print data to the OUTPUT unit (usually the screen when working in interactive mode).
While the spreadsheet formats will use only one (possibly extremely long) line to represent all entries of a series (with ORG=ROWS) or observation (with ORG=COLS), FORMAT=FREE uses multiple lines if necessary to keep the width of the output from getting too large. For instance, this is a segment of the output for a single quarterly data series (this was done with options FORMAT=FREE,ORG=ROWS,DATES):
1947:01 224.9000000 229.1000000 233.3000000 243.6000000
1948:01 249.6000000 257.1000000 264.0000000 265.5000000
1949:01 260.1000000 256.6000000 258.6000000 256.5000000
1950:01 267.4000000 276.9000000 294.5000000 305.9000000
1951:01 319.9000000 327.7000000 334.4000000 338.5000000
FORTRAN Format
FORTRAN format is very similar to free-format with a picture code. It does, however, give you a bit more control over the appearance.
If you use a FORTRAN format with the option DATES, your format must allow for the date string at the start of each line. This is an Aw format, where w is at least 7 for quarterly and other “periods per year” data, 10 for daily, weekly, etc. and 15 for intraday or panel data. In addition, if you use ORG=ROWS with DATES, there is a special option ACROSS which you must set correctly:
ACROSS=number of entries per line [4]
ACROSS indicates the number of data values the format will print per line.
For example, we could display the data above formatted eight across by using COPY with the options FORMAT="(A8,8F8.1)",ACROSS=8,DATES.
1947:01 224.9 229.1 233.3 243.6 249.6 257.1 264.0 265.5
1949:01 260.1 256.6 258.6 256.5 267.4 276.9 294.5 305.9
1951:01 319.9 327.7 334.4 338.5 341.1 341.3 347.0 359.2
1953:01 365.4 368.8 367.8 362.6 362.0 361.8 366.2 375.0
Examples
open copy fooddata.xls
copy(dates,format=xls,org=columns)
writes all series in memory onto an Excel file, labeled with dates. Please note that you have to create an entire spreadsheet or database file with a single instruction—RATS cannot “append” data to an existing spreadsheet.
open copy fooddata.lst
copy(dates,format=free,org=cols)
writes the same series to a text file using free format.
cal(q) 1980
*
open data indexsa.xls
data(org=obs,for=xls)
*
pform inf
# usinf jpinf geinf ukinf frinf itinf cainf
pform infr
# usinfr jpinfr geinfr ukinfr frinfr itinfr cainfr
pform eg
# useg jpeg geeg ukeg freg iteg caeg
pform gdpg
# usgdpg jpgdpg gegdpg ukgdpg frgdpg itgdpg cagdpg
*
open copy g7panel.xls
copy(format=xls,org=columns) / inf infr eg gdpg
This reads a set of quarterly international data arranged as separate series for each country, PFORMS the data into a set of panel series, then exports them into a new spreadsheet file.
open data g10xrate.txt
data(format=prn,nolabels,org=columns) 1 6484 date usxjpn usxfra usxsui usxnld usxuk usxbel usxger usxswe $
usxcan usxita
*
dofor s = usxjpn to usxita
set s = %if(%valid(s{0}),s{0},s{1})
end dofor s
open copy g10xrate.xls
copy(format=xls,org=columns,smpl=date>=791231.and.date<=940401)
This reads a set of exchange rate data, patches over missing values (by repeating the previous value) and creates a spreadsheet over a subrange determined by the coded date on the original file.
Copyright © 2025 Thomas A. Doan