1
+ /************************************************************************************************
2
+ USING NESTED FORMATS
3
+ This program creates a format based other formats for different ranges of data.
4
+ Keywords: PROC FORMAT, FORMAT, VALUE
5
+ SAS Versions: SAS 9, SAS Viya
6
+ Documentation: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=default&docsetId=proc&docsetTarget=p1xidhqypi0fnwn1if8opjpqpbmn.htm
7
+ 1. Create a data set on which to test the new format.
8
+ 2. Use PROC FORMAT with a value statement. This identifies the name of the new format. Provide ranges for which you
9
+ want to assign different formats.
10
+ 3. To nest formats use square brackets to identify the format to be applied to each range.
11
+ 4. In the PROC PRINT apply the format and see the results.
12
+ ************************************************************************************************/
13
+ data payroll ; /*1*/
14
+ infile cards ;
15
+ input EmployeeID EmployeeGender : $1 . Salary BirthDate : date9. HireDate : date9.;
16
+ cards ;
17
+ 120101 M 163040 18AUG1980 01JUL2007
18
+ 120102 M 108255 11AUG1973 01JUN1993
19
+ 120103 M 87975 22JAN1953 01JAN1978
20
+ 120104 F 46230 11MAY1958 01JAN1985
21
+ 120105 F 27110 21DEC1978 01MAY2003
22
+ 120106 M 26960 23DEC1948 01JAN1978
23
+ 120107 F 30475 21JAN1953 01FEB1978
24
+ 120108 F 27660 23FEB1988 01AUG2010
25
+ 120109 F 26495 15DEC1990 01OCT2010
26
+ 120110 M 28615 20NOV1953 01NOV1983
27
+ ;
28
+ run ;
29
+
30
+ proc format ; /*2*/
31
+ value benefit low- '31dec60'd =[weekdate50.] /*3*/
32
+ '01jan61'd - '31dec93'd =[worddate20.]
33
+ '01jan94'd - high='** Not Eligible **'
34
+ ;
35
+ run ;
36
+
37
+ proc print data=payroll;/*4*/
38
+ format Birthdate Hiredate benefit.;
39
+ run ;
0 commit comments