Dear All,
I want to replace 0 by "Zero" and missing values by "M" in the given data using SAS
Please help me to solve this problem.
dummy data is attached for reference.
Just apply the format:
proc format;
value myfmt
0 = "zero"
. = "missing"
;
run;
data Conc;
infile datalines;
input Subject Seq$ form$ period C1 C2 C3 C4 C5 C6 C7 C8 C9 C10;
format c1-c10 myfmt.;
cards;
1 AB A 1 0 0.3 7.2 10.3 11.3 12.1 10.3 12.5 13.5 .
1 AB B 2 0 0 4.8 12.7 17.7 17.8 . 24.4 . .
2 BA B 1 0 1.1 9.6 14.5 15.6 13.4 13.6 14.4 14.3 14.3
2 BA A 2 0 0.4 8.1 16.8 15.4 14.4 12.4 13.9 13.9 15.7
3 AB A 1 0 0 0 14.6 16.1 19.7 18 17.8 15.3 15.1
3 AB B 2 0 0.9 8.1 14.2 17.7 20.4 18.5 15.7 14.2 13.2
4 BA B 1 0 0 3.9 9.2 6.2 7.1 7.7 7.9 . 9.1
4 BA A 2 0 0 0 0 14.3 19.7 17.5 13.7 14.3 12.7
5 AB A 1 0 0.4 3.5 6.7 10.9 12 16.8 . 22.3 18.7
5 AB B 2 0 1.1 6.9 11.3 17.4 16.6 15.1 15.1 15.3 15
;
Create a format and use it:
proc format;
value myfmt
0 = "zero"
. = "missing"
;
run;
Values not covered by the format will be displayed as is with the default format (best12.).
Please provide your example data in code, as data step with datalines, so we can show you tested code.
Dear Sir,
Please find following data in SAS code,
data Conc;
infile datalines delimiter='09'x;
input Subject Seq$ form$ period C1 C2 C3 C4 C5 C6 C7 C8 C9 C10;
cards;
1 AB A 1 0 0.3 7.2 10.3 11.3 12.1 10.3 12.5 13.5 .
1 AB B 2 0 0 4.8 12.7 17.7 17.8 . 24.4 . .
2 BA B 1 0 1.1 9.6 14.5 15.6 13.4 13.6 14.4 14.3 14.3
2 BA A 2 0 0.4 8.1 16.8 15.4 14.4 12.4 13.9 13.9 15.7
3 AB A 1 0 0 0 14.6 16.1 19.7 18 17.8 15.3 15.1
3 AB B 2 0 0.9 8.1 14.2 17.7 20.4 18.5 15.7 14.2 13.2
4 BA B 1 0 0 3.9 9.2 6.2 7.1 7.7 7.9 . 9.1
4 BA A 2 0 0 0 0 14.3 19.7 17.5 13.7 14.3 12.7
5 AB A 1 0 0.4 3.5 6.7 10.9 12 16.8 . 22.3 18.7
5 AB B 2 0 1.1 6.9 11.3 17.4 16.6 15.1 15.1 15.3 15
;;;;
run;
Just apply the format:
proc format;
value myfmt
0 = "zero"
. = "missing"
;
run;
data Conc;
infile datalines;
input Subject Seq$ form$ period C1 C2 C3 C4 C5 C6 C7 C8 C9 C10;
format c1-c10 myfmt.;
cards;
1 AB A 1 0 0.3 7.2 10.3 11.3 12.1 10.3 12.5 13.5 .
1 AB B 2 0 0 4.8 12.7 17.7 17.8 . 24.4 . .
2 BA B 1 0 1.1 9.6 14.5 15.6 13.4 13.6 14.4 14.3 14.3
2 BA A 2 0 0.4 8.1 16.8 15.4 14.4 12.4 13.9 13.9 15.7
3 AB A 1 0 0 0 14.6 16.1 19.7 18 17.8 15.3 15.1
3 AB B 2 0 0.9 8.1 14.2 17.7 20.4 18.5 15.7 14.2 13.2
4 BA B 1 0 0 3.9 9.2 6.2 7.1 7.7 7.9 . 9.1
4 BA A 2 0 0 0 0 14.3 19.7 17.5 13.7 14.3 12.7
5 AB A 1 0 0.4 3.5 6.7 10.9 12 16.8 . 22.3 18.7
5 AB B 2 0 1.1 6.9 11.3 17.4 16.6 15.1 15.1 15.3 15
;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.