SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Transforming a " . " into "missing"

Accepted Solution Solved
Reply
Super Contributor
Posts: 413
Accepted Solution

Transforming a " . " into "missing"

Hi,

Suppose I have the following SAS code:

data numbers;

input id name$;

datalines;

1 A

2 B

3 A

4 .

5 B

6 .

7 B

8 A

9 A

10 .

;

run;


Some names are missing and I have the dot "." that signifies that these names are missing, but is it possible to have instead of the dot the actual word "Missing"?


Thank you




Accepted Solutions
Solution
‎12-17-2014 07:41 PM
Trusted Advisor
Posts: 1,204

Re: Transforming a " . " into "missing"

data numbers;

input id name$;

if name=' ' then name='Missing';

datalines;

1 A

2 B

3 A

4 .

5 B

6 .

7 B

8 A

9 A

10 .

;

run;

View solution in original post


All Replies
Solution
‎12-17-2014 07:41 PM
Trusted Advisor
Posts: 1,204

Re: Transforming a " . " into "missing"

data numbers;

input id name$;

if name=' ' then name='Missing';

datalines;

1 A

2 B

3 A

4 .

5 B

6 .

7 B

8 A

9 A

10 .

;

run;

Super Contributor
Posts: 413

Re: Transforming a " . " into "missing"

Thanks a lot stat@sas!

Super Contributor
Posts: 578

Re: Transforming a " . " into "missing"

Isn't the value for name going to be a period? Shouldn't it be

if name='.' then name='Missing';

Respected Advisor
Posts: 3,777

Re: Transforming a " . " into "missing"

DBailey wrote:

Isn't the value for name going to be a period? Shouldn't it be

if name='.' then name='Missing';

No the $ INFORMAT (variables A and C) reads dot as missing to accommodate list input which needs place holder. 

data dot_or_not;
   input a $ @1 @;
   input b $char2. @1 @;
   input c $2. @1 @;
   w=2;
  
input d $varying2. w;
  
cards;
.  x
.  y
;;;;
   run;
proc print;
  
run;

12-18-2014 7-14-06 AM.png
Super Contributor
Posts: 578

Re: Transforming a " . " into "missing"

nice to know.  I'm figured that STAT wouldn't have made an error like that..but had to ask.

Trusted Advisor
Posts: 1,204

Re: Transforming a " . " into "missing"

Hi DBailey,

Thanks for highlighting this. I also learned as a result of your question from master data_null_.

Regards,

Naeem

Trusted Advisor
Posts: 1,130

Re: Transforming a " . " into "missing"

Alternatively by ifc function

data numbers;

input id name$;

name=ifc(name='','Missing',name);

datalines;

1 A

2 B

3 A

4 .

5 B

6 .

7 B

8 A

9 A

10 .

;

run;

Thanks,

Jag

Thanks,
Jag
Super Contributor
Posts: 413

Re: Transforming a " . " into "missing"

thanks Jagadishkatam, you taught me a new function!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 1357 views
  • 7 likes
  • 5 in conversation