BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jitendrakoli
Fluorite | Level 6

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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
;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

jitendrakoli
Fluorite | Level 6

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;

Kurt_Bremser
Super User

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
;
jitendrakoli
Fluorite | Level 6
Thank you very much

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 811 views
  • 1 like
  • 2 in conversation