This script defines two formats using PROC FORMAT. The 'loads' format defines labels for value ranges. The 'couple' format demonstrates a nesting technique: it applies the 'loads' format for values between 5000 and 10000, handles a specific value (2), and applies a standard 'comma6.' format for other cases. A Data Step _null_ is used to test these formats on internal data.
Data Analysis
Type : CREATION_INTERNE
Data is defined directly in the script via the CARDS statement.
1 Code Block
PROC FORMAT
Explanation : Definition of 'loads' and 'couple' formats. Note the use of square brackets [ ] in 'couple' to dynamically call another format ('loads') or a system format ('comma').
Copied!
proc format ;
value loads
5000-<6000 = 'Over 5,000'
6000-<7000 = 'Over 6,000'
7000-<8000 = 'Over 7,000'
8000-<9000 = 'Over 8,000'
other = 'Mega!' ;
value couple
2 = 'Bingo!'
5000-<10000 = [loads10.]
other=[comma6.] ;
run ;
1
PROC FORMAT ;
2
value loads
3
5000-<6000 = 'Over 5,000'
4
6000-<7000 = 'Over 6,000'
5
7000-<8000 = 'Over 7,000'
6
8000-<9000 = 'Over 8,000'
7
other = 'Mega!' ;
8
9
value couple
10
2 = 'Bingo!'
11
5000-<10000 = [loads10.]
12
other=[comma6.] ;
13
RUN ;
2 Code Block
DATA STEP
Explanation : Execution Data Step that does not create an output table (_null_). It reads in-line data (CARDS) and writes the formatted value of 'x' to the log via the PUT statement.
Copied!
data _null_ ;
input x ;
put x couple. ;
cards;
7777
1234
2
23
;
run ;
1
DATA _null_ ;
2
INPUT x ;
3
put x couple. ;
4
CARDS;
5
7777
6
1234
7
2
8
23
9
;
10
RUN ;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.