Question: I am using the OutWin= option to get CARs or BHARs in a SAS data set, but I would like to include in this file some information from my request file (in addition to the information that the outwin file includes such as cusip, permno, the window dates, and the computed returns), because I need that information for uniquely identifying each record for subsequent data merges.
Solution: You can use the ID= option to specify any one variable from the request file that will be included. As of now that's all; a future version of Eventus may offer multiple ID variable capability.
For now, to prepare for merging by multiple variables, you could create a composite variable for merging purposes only. For example, let's say tag1 is a 1-3 digit integer, tag2 is a 5-character text string and tag3 is a floating point non-negative number <100 with 4 decimal places, and we want to merge by tag1 tag2 tag3 in that order. We could do:
data request;
set request;
composite_id=put(tag1,z3.0) || tag2 || put(tag3,z7.4);
run;
Where request is an existing SAS data set that will be overwritten by a new copy of itself with all the old data plus the added variable. Put a new name in the data statement if you don't want the old copy overwritten.
The put functions are used to achieve consistency in positioning the number within the string so that it will sort and merge properly; in particular the zw.d format pads numbers with leading zeros when needed.
Caution: The maximum length of composite_id is set by the first observation. This is not an issue in the above example, because the use of z formats ensures that the numeric variables always enter composite_id as 3 and 7 characters respectively (assuming their numerical properties are as stated in the first paragraph above). Some other SAS numeric formats conserve space when numbers are shorter and would not be recommended for use in this situation. In situations where you want to declare the maximum length of a character variable instead of allowing it to be implied by the first use, see the length statement in SAS documentation.
The user who asked this question was familiar with merging SAS data sets, information about which is available in SAS documentation.
Comments
0 comments
Article is closed for comments.