Sample 24788: Use formatted value to combine data sets
Merge multiple data sets using the formatted version of
the BY variable(s) rather than the stored value.
Note:
In this sample, the BY variable is a SAS date, therefore
it is stored as the exact number of days from
January 1, 1960. A MERGE based upon the stored value
of date would only consider the exact date as a match.
Merging by a formatted value, such as MONYYw., the
BY group is based upon month and year, rather than the
specific date.
GROUPFORMAT can be specified anywhere on the BY
statement and will apply to all BY variables.
data one;
input date :mmddyy6. x $;
format date date9.;
datalines;
010104 a
011504 b
012804 c
020204 a
022904 b
031304 a
031504 b
;
data two;
input date :mmddyy6. y;
datalines;
011204 111
021504 222
031704 333
;
data three;
format date monyy7.;
merge one two;
by groupformat date;
run;
proc print data=three;
run;
Obs date x y
1 JAN2004 a 111
2 JAN2004 b 111
3 JAN2004 c 111
4 FEB2004 a 222
5 FEB2004 b 222
6 MAR2004 a 333
7 MAR2004 b 333
Merge multiple data sets using the formatted version of
the BY variable(s) rather than the stored value.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> MERGE Common Programming Tasks ==> Combining Data SAS Reference ==> Statements ==> File-handling ==> MERGE ==> with BY
|
| Date Modified: | 2008-01-28 11:44:43 |
| Date Created: | 2004-09-30 14:09:14 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |