The script is divided into three main blocks. The first block uses the `PROC FORMAT` procedure to define a character format named `$test`, which maps the values 'a' and 'c' to their 'Formatted' versions. The second block is a `DATA STEP` that creates a `sasuser.test` dataset. In this `DATA STEP`, a variable `x` is generated with values 'a', 'b', and 'c', and a variable `y` receives a random numeric value. The `$test` format is applied to variable `x`. The third block uses the `PROC PRINT` procedure to display the content of the `sasuser.test` dataset, showing the effect of formatting on variable `x`.
Data Analysis
Type : INTERNAL_CREATION
The `sasuser.test` dataset is created from scratch within the script's DATA STEP. No external data or data from default SAS libraries (like SASHELP) is used as the initial source for this dataset. The `sasuser` library is a default user-specific library where data is generated.
1 Code Block
PROC FORMAT
Explanation : This block defines a custom character format named `$test`. It assigns the label 'Formatted a' to the value 'a' and 'Formatted c' to the value 'c'. Other unspecified values (like 'b') will retain their original value when formatted.
Copied!
proc format ;
value $test
'a'='Formatted a'
'c'='Formatted c' ;
run;
1
PROC FORMAT ;
2
value $test
3
'a'='Formatted a'
4
'c'='Formatted c' ;
5
RUN;
2 Code Block
DATA STEP Data
Explanation : This DATA STEP creates a dataset named `test` in the `sasuser` library. It applies the previously defined `$test` format to variable `x`. A `DO` loop generates three observations, successively assigning 'a', 'b', and 'c' to variable `x`, and a random numeric value (between 0 and 100) to variable `y` using the `RANUNI` function. The `OUTPUT` statement writes each observation to the dataset.
Copied!
data sasuser.test ;
format x $ test. ;
do x='a','b','c';
y=ranuni(1)*100;
output ;
end ;
run ;
1
DATA sasuser.test ;
2
FORMAT x $ test. ;
3
DO x='a','b','c';
4
y=ranuni(1)*100;
5
OUTPUT ;
6
END ;
7
RUN ;
3 Code Block
PROC PRINT
Explanation : This `PROC PRINT` procedure displays the content of the `sasuser.test` dataset. The values of variable `x` will appear formatted according to the `$test` format (e.g., 'Formatted a' instead of 'a', and 'Formatted c' instead of 'c').
Copied!
proc print data=sasuser.test ;run;
1
PROC PRINTDATA=sasuser.test ;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.