Consider the data given below
Name Gender
John 1
Ram 1
Geetha 0
Nithin 1
Meena 0
In this data
‘0’ and ‘1’ represents “ Female” and “Male “ respectively. We need to change
those 0’s and 1’s by their respective labels. For this we can use FORMAT command in SAS.
libname
mylib "D:\sas\";/*Creating
a library named mylib*/
data
mylib.file1;/*Storing the given data into file1*/
input
name$ gender;
datalines;
John 1
Ram 1
Geetha 0
Nithin 1
Meena 0
;
run;
proc format;/*Creating
a format named sex*/
value sex
0='female'
1='male'
;
run;
proc print data=mylib.file1;
format
gender sex.;/*Format is applying to the variable gender*/
run;
These codes
can only format the output. If you want to make changes in the file, use the
follwing code given below.
data
mylib.file1;
set mylib.file1;
format gender sex.;
run;
If you are using “ data
mylib.file2; ” instead of “ data mylib.file1; ” then SAS will create a new file
named ‘file2’ and a formatted version of this data will save into it.